Как пройти данные профиля пользователя с дополнительным контекстом в универсальных видах на основе классов?

StackOverflow https://stackoverflow.com//questions/9647159

Вопрос

У меня есть модель:

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 }}.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top