开发者

How can I disable the "Recent Actions" widget from Django Admin interface?

开发者 https://www.devze.com 2023-03-20 02:36 出处:网络
I dont want to s开发者_StackOverflowhow the recent action widget in django admin site.I don\'t know how to get this done.you can override the admin/index.html template to disable the display. There\'s

I dont want to s开发者_StackOverflowhow the recent action widget in django admin site.I don't know how to get this done.


you can override the admin/index.html template to disable the display. There's a sidebar block you might want to change/remove.

Conditionally enabling or disabling actions ModelAdmin.get_actions(request) Finally, you can conditionally enable or disable actions on a per-request (and hence per-user basis) by overriding ModelAdmin.get_actions().

This returns a dictionary of actions allowed. The keys are action names, and the values are (function, name, short_description) tuples.

Most of the time you'll use this method to conditionally remove actions from the list gathered by the superclass. For example, if I only wanted users whose names begin with 'J' to be able to delete objects in bulk, I could do the following:

class MyModelAdmin(admin.ModelAdmin):
    ...

    def get_actions(self, request):
        actions = super(MyModelAdmin, self).get_actions(request)
        if request.user.username[0].upper() != 'J':
            del actions['delete_selected']
        return actions

i edited the answer you may find more like this at https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/


Expanding on the answer given by @Devjosh. To override existing template, all you have to do is create templates/admin folder and add index.html in it with these lines to get rid of Recent Actions sidebar:-

{% extends "admin/index.html" %}

{% block sidebar  %}
{% endblock %}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号