Skip to content

Commit

Permalink
feat: changeform before/after templates (#726)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Sep 13, 2024
1 parent 26f79a6 commit 0b56e65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/unfold/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ class ModelAdmin(ModelAdminMixin, BaseModelAdmin):
list_filter_submit = False
list_fullwidth = False
list_disable_select_all = False
change_form_before_template = None
change_form_after_template = None
compressed_fields = False
readonly_preprocess_fields = {}
warn_unsaved_form = False
Expand Down
9 changes: 8 additions & 1 deletion src/unfold/templates/admin/change_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}{% if form_url %}action="{{ form_url }}" {% endif %}method="post" id="{{ opts.model_name }}_form" {% if adminform.model_admin.warn_unsaved_form %}class="warn-unsaved-form"{% endif %} novalidate>
{% csrf_token %}

{% if adminform.model_admin.change_form_before_template %}
{% include adminform.model_admin.change_form_before_template %}
{% endif %}

{% block form_top %}{% endblock %}

<div>
Expand Down Expand Up @@ -94,11 +98,14 @@
{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% endfor %}

{% endblock %}

{% block after_related_objects %}{% endblock %}

{% if adminform.model_admin.change_form_after_template %}
{% include adminform.model_admin.change_form_after_template %}
{% endif %}

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

{% block admin_change_form_document_ready %}
Expand Down

0 comments on commit 0b56e65

Please sign in to comment.