Answer the question
In order to leave comments, you need to log in
How to program a button in Django admin?
Good day,
I can't figure out how to trigger an action on a button in the Django admin panel. I overridden
change_list.html for the model:
{% extends "admin/change_list.html" %}
{% load i18n admin_urls %}
{% block object-tools %}
{% if has_add_permission %}
<ul class="object-tools">
{% block object-tools-items %}
<li>
<button type="submit" name="getShard" value="getShard" class="button">Get Shard</button>
</li>
<li>
<button type="submit" name="refreshShard" value="refreshShard" class="button">Refresh Shard</button>
</li>
{% endblock %}
</ul>
{% endif %}
{% endblock %}
def getShard():
pass
def refreshShard():
pass
Answer the question
In order to leave comments, you need to log in
so after all pass inactivity. instead of a pass, write a redirect at least
class MyModelAdmin(admin.ModelAdmin):
def get_urls(self):
urls = super().get_urls()
shard_urls = [
url(r'^get_shard/$', getShard),
url(r'^refresh_shard/$', refreshShard),
]
return shard_urls + urls
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question