0

I'm trying to find a way to handle on admin logout (django admin page), files in a certain folder will get deleted. Because i have a function on certain admin interactions, files will get saved to a folder and i would like these files to get deleted when the admin logging out of the admin page.

I only know about Django detect user logout on browser close like so:

if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:

What i would like to do is to override the logout function of admin site to execute a function and delete files in a folder. I can see that the logout function exists in https://github.com/django/django/blob/master/django/contrib/admin/sites.py#L349 but how do i override it and add my delete files function into it ?

Linh Nguyen
  • 3,452
  • 4
  • 23
  • 67

1 Answers1

2

If you want to override the logout function itself, you'll have to subclass the AdminSite class and create your own class with overriding implementation of logout.

Check this for how to customize AdminSite: How to use custom AdminSite class?

You can also use the logout signal to run addition functions after user logout.

Check: https://docs.djangoproject.com/en/dev/ref/contrib/auth/#module-django.contrib.auth.signals

Abhishek Menon
  • 753
  • 4
  • 15