[Answered ]-Django change / override the delete link within a model

2๐Ÿ‘

โœ…

You can override the delete url in submit_line.html file. The file can be found in /django/contrib/admin/templates/admin/ folder of your django installation. Copy this file to your templates folder, so it will look like /your_templates_folder/admin/submit_line.html. The line which displays the delete button is

{% if show_delete_link %}
    <p class="deletelink-box">
        <a href="{% url opts|admin_urlname:'delete' original.pk|admin_urlquote %}" class="deletelink">
            {% trans "Delete" %}
        </a>
    </p>
{% endif %}

You can change the href url to the delete url of your choice. For example

{% if show_delete_link %}
    <p class="deletelink-box">
        <a href="/your_delete_link/{{ original.pk }}/" class="deletelink">
            {% trans "Deleted" %}
        </a>
    </p>
{% endif %}
๐Ÿ‘คarulmr

0๐Ÿ‘

Just make your view on the same url, and place it before admin in urlconf.

๐Ÿ‘คNik

Leave a comment