How to add edit and delete buttons in django admin

Question:

I want to add 2 buttons in django admin, like on this screenshot, but instead of "Deposit" and "Withdraw" there should be "Edit" and "Delete"

I found lots of answers how to add custom actions, but is there a proper way to add such buttons? All methods for them are written, it seems to me that this two buttons should be added mush more easier.

enter image description here
picture came from here:
https://medium.com/@hakibenita/how-to-add-custom-action-buttons-to-django-admin-8d266f5b0d41

but I’m interested in easier solution, if such exists

Asked By: Ilya Osipov

||

Answers:

list_display from here provides me to add smth for every object. So I added this in my MyModelAdmin:

def change_button(self, obj):
    return format_html('<a class="btn" href="/admin/my_app/my_model/{}/change/">Change</a>', obj.id)

def delete_button(self, obj):
    return format_html('<a class="btn" href="/admin/my_app/my_model/{}/delete/">Delete</a>', obj.id)

list_display = ('__str__', 'change_button', 'delete_button')

And now this two buttons are added. This is still not the best way I guess, but mush easier then adding any other action.

Answered By: Ilya Osipov