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

Gul Asnani
Gul Asnani
15,138 Points

Django models stacked inline of other models

In the Django basics course, when we create models with a foreign key to another model, like the Step model had a Foreign Key to Course model, a many to one relationship, when we made urls for the step details, we wrote course_pk/step_pk. Since step is a model in itself, it's primary key will be continuous irrespective of which course it relates to.

So when I do courses/2/1, it gives me the first step in second course but courses/1/1 doesn't give me the first step in the first course because I created steps for the second course before and hence their primary keys begin from 1. There are two steps in each course and the second ones were created first, so courses/1/3 gives me my first step in first course. Is there any way I can change this and make it more user friendly?