1

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Vlad T.
  • 2,568
  • 3
  • 26
  • 40

1 Answers1

2

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

Berislav Lopac
  • 16,656
  • 6
  • 71
  • 80