I have added a custom button in django admin, however its below the Save and Save and Close buttons, how can I make this custom button on the same line with the 2 buttons above, below is the image:
Then, how I overridden the button with the templates:
JavaScript
x
13
13
1
{% extends 'admin/custominlines/change_form.html' %}
2
{% load i18n %}
3
{% block submit_buttons_bottom %}
4
{{ block.super }}
5
{% if request.GET.edit %}
6
<div class="submit-row">
7
{% for obj in transitions %}
8
<input type="submit" value="{{ obj }}" name="{{ obj }}">
9
{% endfor %}
10
</div>
11
{% endif %}
12
{% endblock %}
13
Advertisement
Answer
Django has a <div class="submit-row">
for each row. You are adding a new row. What you need to do is to put your buttons in the same div
with Django. Here is Django’s code modified to have your buttons.
JavaScript
1
22
22
1
{% load i18n admin_urls %}
2
<div class="submit-row">
3
{% block submit-row %}
4
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save">{% endif %}
5
{% if show_delete_link and original %}
6
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
7
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
8
{% endif %}
9
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew">{% endif %}
10
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother">{% endif %}
11
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% trans 'Save and continue editing' %}{% else %}{% trans 'Save and view' %}{% endif %}" name="_continue">{% endif %}
12
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% trans 'Close' %}</a>{% endif %}
13
{% endblock %}
14
// Django code above
15
16
// Your buttons below
17
{% for obj in transitions %}
18
<input type="submit" value="{{ obj }}" name="{{ obj }}">
19
{% endfor %}
20
21
</div>
22
Your code at the end will look like this.
JavaScript
1
26
26
1
{% extends 'admin/custominlines/change_form.html' %}
2
{% load i18n %}
3
{% block submit_buttons_bottom %}
4
<div class="submit-row">
5
6
{% if show_save %}<input type="submit" value="{% trans 'Save' %}" class="default" name="_save">{% endif %}
7
{% if show_delete_link and original %}
8
{% url opts|admin_urlname:'delete' original.pk|admin_urlquote as delete_url %}
9
<p class="deletelink-box"><a href="{% add_preserved_filters delete_url %}" class="deletelink">{% trans "Delete" %}</a></p>
10
{% endif %}
11
{% if show_save_as_new %}<input type="submit" value="{% trans 'Save as new' %}" name="_saveasnew">{% endif %}
12
{% if show_save_and_add_another %}<input type="submit" value="{% trans 'Save and add another' %}" name="_addanother">{% endif %}
13
{% if show_save_and_continue %}<input type="submit" value="{% if can_change %}{% trans 'Save and continue editing' %}{% else %}{% trans 'Save and view' %}{% endif %}" name="_continue">{% endif %}
14
{% if show_close %}<a href="{% url opts|admin_urlname:'changelist' %}" class="closelink">{% trans 'Close' %}</a>{% endif %}
15
16
// Django code above
17
18
// Your buttons below
19
20
{% for obj in transitions %}
21
<input type="submit" value="{{ obj }}" name="{{ obj }}">
22
{% endfor %}
23
24
</div>
25
{% endblock %}
26