From 2799270bb8029dc2ff3e306c737aec0825fdf2d2 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sun, 2 Apr 2023 18:28:02 +0200 Subject: [PATCH] Refresh cache when clearing/generating data --- src/purchase/management/commands/clear_all_data.py | 3 ++- src/purchase/management/commands/generate_dummy_baskets.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/purchase/management/commands/clear_all_data.py b/src/purchase/management/commands/clear_all_data.py index 9b03553..9757452 100644 --- a/src/purchase/management/commands/clear_all_data.py +++ b/src/purchase/management/commands/clear_all_data.py @@ -1,6 +1,6 @@ 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): @@ -11,6 +11,7 @@ class Command(BaseCommand): self.delete(Basket) self.delete(Product) self.delete(PaymentMethod) + Cache.get_solo().refresh() def delete(self, cls): _, count = cls.objects.all().delete() diff --git a/src/purchase/management/commands/generate_dummy_baskets.py b/src/purchase/management/commands/generate_dummy_baskets.py index 7c9c75f..c466037 100644 --- a/src/purchase/management/commands/generate_dummy_baskets.py +++ b/src/purchase/management/commands/generate_dummy_baskets.py @@ -7,7 +7,7 @@ from django.core.management import call_command from django.core.management.base import BaseCommand 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): @@ -25,6 +25,7 @@ class Command(BaseCommand): with freezegun.freeze_time(now() + timedelta(hours=hour)): count += self.generate_baskets(payment_methods, products) + Cache.get_solo().refresh() self.stdout.write(self.style.SUCCESS(f"Successfully created {count} baskets.")) def delete(self, cls):