Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

How to get objects of model one in model two form which are linked with one to many relationship? In Django

I am having two models Patient and Ipd, both are having different unique id and both are created using Forms , First form creates patient object and I want to create Ipd Form which is linked to Patient with patient id with one to many relationship i.e one patient can have multiple Ipd , I not getting how to get patient objects in Ipd Form and create ipd Object which are linked to Patient , I hope you will understant my problem

1 Answer

Can you post your model code? Do you have a foreign key setup? Typically I would have that setup on the primary side which in this case would be the Patient.