Agos
Agos

Reputation: 19450

Django modelform: is inline adding related model possible?

I really hope this is not a duplicate: I couldn't find anything but that could just mean I'm not good at searching :)

I have a Django app, and the staff is already using the admin app for... well, administration purposes.
I also created a quick data entry page for a specific model, created substantially by dropping a modelform inside the base template, so that I have:

...with minimal effort; I know that the admin page can be customized to obtain all this things, but since I have these needs for one operation (insertion) on one model, this was clearly the winning solution.

The problem arises from the fact that this model has two ForeignKeys to other models in the app.
The modelform render this by default with a select with the related model instances: is it possible to have in my Form/ModelForm the ability to add an instance of the related model in the same way that the Django admin does by default? Or should I do over the thing using the Django admin?

This is intended for use by the editorial staff, and I really can understand them when they say they don't want to make round trips between two pages.

Upvotes: 3

Views: 2755

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599956

Well, since the admin is written in Django itself, it is possible to do anything in your own code that you can do in Django.

I think you just need to read the documentation on inline formsets.

Upvotes: 2

Related Questions