Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop logging Recent actions and History in Django 2.* admin panel?

to all!

I'm using Django 2.* and have no idea how to remove this useless for me logging features from Django Admin panel.

I need completely stop tracking all recent actions and logging history in Django admin panel.

Please help me find out a solution. (i've Googled well enough before asking for help here)

History in Django admin Recent actions in Django admin

like image 634
Denis Avatar asked Feb 28 '18 07:02

Denis


People also ask

How do I set up logging in Django?

By default, Django uses the dictConfig format. In order to configure logging, you use LOGGING to define a dictionary of logging settings. These settings describe the loggers, handlers, filters and formatters that you want in your logging setup, and the log levels and other properties that you want those components to have.

How do I change an object in Django admin?

The basic workflow of Django’s admin is, in a nutshell, “select an object, then change it.” This works well for a majority of use cases. However, if you need to make the same change to many objects at once, this workflow can be quite tedious.

How do I delete a selected object in Django?

In these cases, Django’s admin lets you write and register “actions” – functions that get called with a list of objects selected on the change list page. If you look at any change list in the admin, you’ll see this feature in action; Django ships with a “delete selected objects” action available to all models.


1 Answers

These logging entries are created in 3 methods of ModelAdmin: log_addition, log_change and log_deletion. So what you need to do is override them in all of your admin classes inheriting form ModelAdmin and simply return in the body of these methods.

If you have more than a few admin classes, you can make a mixin class that overrides these methods and inherit from it in all your admin classes. Note that you need to inherit from the mixin before admin.ModelAdmin.

For example:

class DontLog:
    def log_addition(self, *args):
        return

    # Do same for log_change and log_deletion

@admin.register(Category)
class CategoryAdmin(DontLog, admin.ModelAdmin):
    pass

To remove history buttons, you'll want to edit the template as described in the admin docs linked to in one of the comments to your question:

https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#overriding-vs-replacing-an-admin-template

like image 175
Rainy Avatar answered Oct 08 '22 01:10

Rainy