Как пройти данные профиля пользователя с дополнительным контекстом в универсальных видах на основе классов?
-
10-12-2019 - |
Вопрос
У меня есть модель:
class Schedule(models.Model):
begins_at = models.DateTimeField()
instructor = models.ForeignKey(User)
.
Профиль пользователя:
class InstructorProfile(models.Model):
user = models.ForeignKey(User, unique=True)
level = models.CharField()
.
и классовые общие виды в URLS.PY:
url(r'^schedule/(?P<slug>[-\w]+)/$', DetailView.as_view(model=Schedule)),
.
Как я могу пройти уровень инструктора с дополнительным контекстом на мой шаблон?
Решение
The question has nothing to do with the class-based views, it's a simple matter of accessing a user profile. If your user profile is defined in the settings file as the AUTH_PROFILE_MODULE, then in the template you access it simply as {{ schedule.instructor.get_profile }}
.
Не связан с StackOverflow