开发者

Django modelform: is inline adding related model possible?

开发者 https://www.devze.com 2022-12-19 01:33 出处:网络
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 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.开发者_StackOverflow社区


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消