Is there a way to have separate pages for inline admin forms in Django?

Suppose I have model A. Then I have several models B, C, D, E, etc., each of which has a foreign key for model A. I know that I can install B, C, D etc. as built-in to model A, so when I create model A, it will show formets for adding several elements for each subModel, but I think it will create a rather cluttered and very large page.

Is there a way somehow, instead of having all these inline forms on one page, having each set of forms on a separate page? In other words, would there be links from model A to create / edit an associated model B, create / edit a related model C, etc.?

Thanks!

+4
source share
2 answers

I need a way to do the same. It seems that the answer may be "proxy models." He suggested in response to this request:

django admin: separate view and read-only view

... and this query queries multiple admin lists for the same model:

Multiple ModelAdmins / views for the same model in Django admin

Proxy model documentation here:

Django | Models | Django Documentation # Proxies

I'm new to Django, so I'll post a more complete answer as soon as I earn it.

+2
source

Trivial answer: create file:

${TEMPLATE_DIR}/admin/app/modelA/change_form.html 

Inside your change form, you do the following:

 {% extends "admin/change_form.html" %} {% block after_related_objects %} <ul> <li><a href="/admin/app/modelB/{{ original.modelB.id }}/">Edit modelB</a></li> </ul> {% endblock %} 

This is a kind of primitive, but it does what you want. Lists and complex aggregations are more complex, and you want to check for the availability of the original to make sure that you are not generating template errors.

0
source

Source: https://habr.com/ru/post/1309475/


All Articles