Populating parent model from child model in django

I have a web interface in which I can add entries to a child model, which I created in Django. I can populate the child model by using dropdown menus which will display the items currently stored in the parent models. I would like to be able to actually insert a new item in the parent model from within the same form.

As you see in the picture this is the rendered form in which I can create a new “result”. The entries “object_id” and “type_id” in the correspondent “results” model are ForeignKeys and are rendered as dropdown menus. From the same page, I would like to have the possibility to add a new value to “object_id” or “type_id” instead of only reading the values stored in the parents’ models. Is there a way of doing this?

The short answer is “Yes”, it can be done. You can see how it’s done by examining the Admin pages for forms referencing related objects through Foreign Keys. (They show up in the pages as a green “+” icon next to the field in the form.)

You can also replace the “Select” widget being rendered for that form with a Widget that allows for the entry of a field that doesn’t currently exist. You’ll have to do some work in your form to not have that field rejected due to a validation error, but it all can be done.