Relative Content

Tag Archive for pythondjangoforeign-keys

How to pull up Django model data based on ALREADY filled out form fields for other ForeignKeys

I have a form in which there are several fields with foreign keys. For example, the table “Entrance” (3 entries -> 1st entrance, 2nd entrance, 3rd entrance), “Apartment” (30 entries, 10 for each entrance (No.1-10, No. 11-20 and No. 21-30), “Owner” (also 30 entries of surnames). In turn, the “Owner” has an external key to the apartment, and the “Apartment” has an external key to the entrance. here’s the question, if I selected entrance No. 2 in the form, then in the other two fields (Apartment and Owner) I need to display ONLY related records (that is, apartments from 11 to 20 rooms, and the owners who live in these apartments) how to implement it???