Refresh cache when clearing/generating data

This commit is contained in:
Gabriel Augendre 2023-04-02 18:28:02 +02:00
parent 4c4cd1ca03
commit 2799270bb8
2 changed files with 4 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from purchase.models import Basket, BasketItem, PaymentMethod, Product from purchase.models import Basket, BasketItem, Cache, PaymentMethod, Product
class Command(BaseCommand): class Command(BaseCommand):
@ -11,6 +11,7 @@ class Command(BaseCommand):
self.delete(Basket) self.delete(Basket)
self.delete(Product) self.delete(Product)
self.delete(PaymentMethod) self.delete(PaymentMethod)
Cache.get_solo().refresh()
def delete(self, cls): def delete(self, cls):
_, count = cls.objects.all().delete() _, count = cls.objects.all().delete()

View file

@ -7,7 +7,7 @@ from django.core.management import call_command
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from django.utils.timezone import now from django.utils.timezone import now
from purchase.models import Basket, BasketItem, PaymentMethod, Product from purchase.models import Basket, BasketItem, Cache, PaymentMethod, Product
class Command(BaseCommand): class Command(BaseCommand):
@ -25,6 +25,7 @@ class Command(BaseCommand):
with freezegun.freeze_time(now() + timedelta(hours=hour)): with freezegun.freeze_time(now() + timedelta(hours=hour)):
count += self.generate_baskets(payment_methods, products) count += self.generate_baskets(payment_methods, products)
Cache.get_solo().refresh()
self.stdout.write(self.style.SUCCESS(f"Successfully created {count} baskets.")) self.stdout.write(self.style.SUCCESS(f"Successfully created {count} baskets."))
def delete(self, cls): def delete(self, cls):