AlexW AlexW -4 years ago 111
Python Question

Django Admin - add a new block that can be set in admin.py?

ive copied the change_form from the admin dir into my own dir. Ive added a new block named extra_content as per the below

{% block inline_field_sets %}
{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% endfor %}
{% endblock %}

{% block after_related_objects %}{% endblock %}

{% block extra_content %}
{% include '{{ ?? }}' %}
{% endblock %}

{% block submit_buttons_bottom %}{% submit_row %}{% endblock %}


inside that block i have an include, and i was wondering if i could set what file that include would pull in admin.py?

Thanks

Answer Source

I think you can do by override change_view

class MyModelAdmin(admin.ModelAdmin):
    def change_view(self, request, object_id, form_url='', extra_context=None):
        extra_context = extra_context or {}
        extra_context['include_template'] = '/path/to/.html'
        return super(MyModelAdmin, self).change_view(
            request, object_id, form_url, extra_context=extra_context,
        )

Then in template

{% include include_template %}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download