Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms Model Forms Using a Model Form

in this session, quiz.course = course. Just wondering, is there an attribute in quiz model named course? I didnt see it

in this session, quiz.course = course. Just wondering, is there an attribute in quiz model named course? I didnt see it defined in the quiz model Or quiz.course = course will assign the pk of course to quiz.course (foreign key)? how django or python define this. Any material I can read these tricks?

1 Answer

Hi there, still learning this myself so I apologise if I give you a wrong steer.

Quiz inherits from Step which has a foreign key course to the Course model.

So if you go into the Shell and import Quiz and Step then you can check that chain as follows:

>>> from courses.models import Quiz, Step
>>> q = Quiz.objects.get(id=1)
>>> q.title
'Review'
>>> q.description
'A quick review'
>>> q.course
<Course: Python Basics>
>>> q.course.title
'Python Basics'
>>>

As can be seen above q.course gives back the object Course

Hope that helps some!