Add management commands
This commit is contained in:
parent
f4a0edd091
commit
ec6acaf8ea
2 changed files with 54 additions and 0 deletions
21
gallery/management/commands/clear_album_cache.py
Normal file
21
gallery/management/commands/clear_album_cache.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from django.core.cache import cache
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from gallery.models import Album
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Clears photo count and view count caches for all albums"
|
||||
|
||||
def handle(self, *args, **options):
|
||||
albums = Album.objects.only("pk", "name")
|
||||
cleared = 0
|
||||
|
||||
for album in albums:
|
||||
cache.delete(f'album_{album.pk}_photo_count')
|
||||
cache.delete(f'album_{album.pk}_photo_views')
|
||||
cleared += 1
|
||||
|
||||
self.stdout.write(self.style.SUCCESS(
|
||||
f"Cleared cache for {cleared} albums."
|
||||
))
|
Loading…
Add table
Add a link
Reference in a new issue