views:

188

answers:

1

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:

  • custom fields
  • custom widgets
  • javascript client-side validation (server-side validation is of course also present)
  • and of course my page layout.

...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.

A: 

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.

Daniel Roseman
Inline formsets aren't a solution for a number of reasons. 1) They give you the ability to edit the original model from the related, not vice versa! 2) They just give the option to add new items and not choosing existing ones
Agos
@Agos - ad 1. not nescesarly - you can add readonly_fields property to the inline admin.
bx2