Add management commands

This commit is contained in:
Nyymix 2025-04-14 18:52:27 +03:00
parent f4a0edd091
commit ec6acaf8ea
2 changed files with 54 additions and 0 deletions

View 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."
))