Django form - in-place edit of data from reverse foreign key join
-
05-07-2019 - |
Question
I have a Person table and Phone table. The Phone table has a foreign key into the Person table, which is an auto-increment ID. Each person can have an arbitrary number of phone numbers. Is there a way for me to create a Django form to enter phone numbers while creating a new Person entry and edit them along with an existing Person entry?
Solution
Yes, Django's inlineformset_factory is exactly what you need.
Docs: Model Formsets and Inline formsets
This snippet should help you as an example.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow