I want to enable/disable history from django admin button based on the type of user.
My end goal here is to be able to understand how to show hide this button.
Unfortunately, Django does not provide an easy way to toggle History button like it is done for 'Add' button, for instance. The easiest way would be to overwrite a change_form.html and remove the next lines from block object-tools-items
:
<li>
{% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
<a href="{% add_preserved_filters history_url %}" class="historylink">{% trans "History" %}</a>
</li>
Keep in mind that you have to specify change_form
for every admin model.
Example:
class TestAdmin(admin.ModelAdmin):
# path to the app_name/templates/admin/app_name/change_form.html
change_form_template = 'admin/app_name/change_form.html'
# Register your models here.
admin.site.register(Test, TestAdmin)