Closed ErwinKomen closed 7 years ago
It was difficult to find a good solution, but I found one description at https://linevi.ch/en/django-inline-in-fieldset.html.
Basically the steps are:
django/contrib/admin/templates/admin/change_form.html
to a directory [application_root]/templates/admin/[package]/[app_name]
django/contrib/admin/templates/admin/includes/fieldset.html
to a directory [application_root]/templates/admin/includes
django/contrib/admin/templates/admin/edit_inline/tabular.html
to a directory [application_root]/templates/admin/edit_inline
admin.TabularInline
classes in admin.py
add a line insert_after = 'name_of_field'
, where the name of the field after which the inline should come appearschange_form.html
in this way:{% block field_sets %}
{% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" with inline_admin_formsets=inline_admin_formsets %}
{% endfor %}
{% endblock %}
`
{% block after_field_sets %}{% endblock %}
{% block inline_field_sets %}
{% for inline_admin_formset in inline_admin_formsets %}
{% if not inline_admin_formset.opts.insert_after %}
{% include inline_admin_formset.opts.template %}
{% endif %}
{% endfor %}
{% endblock %}`
Insert the following just preceding the penultimate endfor
statement:
{# Insert inlines after the field #}
{% for inline_admin_formset in inline_admin_formsets %}
{% if inline_admin_formset.opts.insert_after == field.field.name %}
{% include inline_admin_formset.opts.template with subordinate_formset=subordinate_formset %}
{% endif %}
{% endfor %}
The
Descriptor
details form should be re-ordered such, that it reflects the specified order provided by Henk van den Heuvel.