Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: submit line cancel button #990

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/configuration/modeladmin.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class CustomAdminClass(ModelAdmin):
# Dsable select all action in changelist
list_disable_select_all = False


# Custom actions
actions_list = [] # Displayed above the results list
actions_row = [] # Displayed in a table row in results list
Expand All @@ -63,6 +62,9 @@ class CustomAdminClass(ModelAdmin):
change_form_outer_before_template = "some/template.html"
change_form_outer_after_template = "some/template.html"

# Display cancel button in submit line in changeform
change_form_show_cancel_button = True # show/hide cancel button in changeform, default: False

formfield_overrides = {
models.TextField: {
"widget": WysiwygWidget,
Expand Down
29 changes: 15 additions & 14 deletions src/unfold/templates/admin/submit_line.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@
</button>
{% endif %}

{% if show_close %}
{% url opts|admin_urlname:'changelist' as changelist_url %}

<a href="{% add_preserved_filters changelist_url %}" class="border border-base-200 font-medium px-3 py-2 rounded transition-all w-full hover:bg-base-50 lg:block lg:w-auto dark:border-base-700 dark:hover:text-base-200 dark:hover:bg-base-900">
{% translate 'Close' %}
</a>
{% endif %}

{% if show_save_and_add_another %}
<button type="submit" name="_addanother" class="border border-base-200 font-medium px-3 py-2 rounded transition-all w-full hover:bg-base-50 lg:block lg:w-auto dark:border-base-700 dark:hover:text-base-200 dark:hover:bg-base-900">
{% translate 'Save and add another' %}
Expand All @@ -47,15 +39,24 @@
</button>
{% endif %}

{% if show_delete_link and original %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
<div class="flex flex-col gap-3 mr-auto w-full lg:flex-row lg:w-auto">
{% if show_close or adminform.model_admin.change_form_show_cancel_button %}
{% url opts|admin_urlname:'changelist' as changelist_url %}

<a href="{% add_preserved_filters changelist_url %}" class="border border-base-200 font-medium px-3 py-2 rounded text-center transition-all w-full hover:bg-base-50 lg:block lg:w-auto dark:border-base-700 dark:hover:text-base-200 dark:hover:bg-base-900">
{% translate 'Close' %}
</a>
{% endif %}

{% if show_delete_link and original %}
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}

<p class="deletelink-box mr-auto w-full lg:w-auto">
<a href="{% add_preserved_filters delete_url %}" class="bg-red-600 flex items-center justify-center font-medium h-9.5 ml-auto px-3 py-2 rounded text-white dark:bg-red-500/20 dark:text-red-500">

<a href="{% add_preserved_filters delete_url %}" class="bg-red-600 flex items-center justify-center font-medium h-9.5 ml-auto px-3 py-2 rounded text-center text-white w-full lg:w-auto dark:bg-red-500/20 dark:text-red-500">
{% translate "Delete" %} {{ opts.verbose_name }}
</a>
</p>
{% endif %}
{% endif %}
</div>
{% endblock %}
</div>
</div>
Expand Down
Loading