我已将admin目录中的change_form复制到我自己的目录中。我添加了一个名为extra_content的新块,如下所示
{% 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 %}
在该块中我有一个包含,我想知道我是否可以设置包含哪个文件会拉入admin.py?
由于
答案 0 :(得分:1)
我认为您可以通过覆盖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,
)
然后在模板中
{% include include_template %}