Skip to content

Instantly share code, notes, and snippets.

@cassus
Last active August 29, 2015 13:57
Show Gist options
  • Save cassus/9757672 to your computer and use it in GitHub Desktop.
Save cassus/9757672 to your computer and use it in GitHub Desktop.
Action button on django model edit page
class MyAdmin(admin.ModelAdmin):
def response_change(self, request, obj):
if "_activate_and_send_email" in request.POST:
self.activate_account_and_send_email(request, (obj,))
return HttpResponseRedirect(request.path)
return super().response_change(request, obj)
## In templates/admin/submit_line.html
...
{% if opts.model_name == "myModel" %}<input type="submit" value="{% trans 'Activate and send email' %}" class="btn btn-warning" name="_activate_and_send_email" {{ onclick_attrib }}/>{%endif%}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment