开发者

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

Lets say i have a model A. Then, i have several models B, C, D, E etc that each have a foreignKey to model A. I know that i can set B, C, D etc as inlines to model A so that when i create a model A it will show formsets for adding multiple items开发者_如何学Python for each subModel, but i think this would make a fairly cluttered and very large page.

Is there a way to somehow, instead of having all of these formsets inline on the same page, to have each formset on a separate page? in other words, there would be links from model A to create/edit associate model B's, create/edit associated model C's, etc?

Thanks!


I’m looking for a way to do exactly the same thing. It looks like the answer might be 'proxy models'. It's suggested as an answer to this Stack Overflow query:

django admin: separate read-only view and change view

…and this query asking about multiple admin lists for the same model:

Multiple ModelAdmins/views for same model in Django admin

Documentation on Proxy Models here:

Django | Models | Django documentation#Proxy models

I’m a newcomer to Django myself, so will post a more complete reply once I get it to work.


The trivial answer would be to create a file:

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

Inside your change form, you do this:

{% 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 %}

It's kinda primitive, but it does what you want. Lists and complex aggregations are trickier, and you'd want to test for original's presence to make sure you don't generate template errors.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜