Search code examples
djangodjango-class-based-viewsuser-profiledjango-context

how do I pass user profile data with extra context in class-based generic views?


I have model:

class Schedule(models.Model):
    begins_at = models.DateTimeField()
    instructor = models.ForeignKey(User)

user profile:

class InstructorProfile(models.Model):
    user = models.ForeignKey(User, unique=True)
    level = models.CharField()

and class-based generic views in urls.py:

url(r'^schedule/(?P<slug>[-\w]+)/$', DetailView.as_view(model=Schedule)),

How can I pass InstructorProfile level with extra context to my template?


Solution

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