Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove history button from Django admin

I want to enable/disable history from django admin button based on the type of user.

enter image description here

My end goal here is to be able to understand how to show hide this button.

like image 547
ofnowhere Avatar asked Nov 26 '17 10:11

ofnowhere


People also ask

How can I remove extra's from Django admin panel?

Take a look at the Model Meta in the django documentation. Within a Model you can add class Meta this allows additional options for your model which handles things like singular and plural naming. Show activity on this post. inside model.py or inside your customized model file add class meta within a Model Class.

How do you remove save and add another Django admin?

The simplest option is to set save_as=True on the ModelAdmin . This will replace the "Save and add another" button with a "Save as new" button.

How do I restrict access to admin pages in Django?

Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .


1 Answers

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)
like image 192
taras Avatar answered Oct 02 '22 01:10

taras