checkout/src/purchase/management/commands/clear_all_data.py
2023-03-25 20:01:14 +01:00

18 lines
537 B
Python

from django.core.management.base import BaseCommand
from purchase.models import Basket, BasketItem, PaymentMethod, Product
class Command(BaseCommand):
help = "Clear all data" # noqa: A003
def handle(self, *args, **options): # noqa: ARG002
self.delete(BasketItem)
self.delete(Basket)
self.delete(Product)
self.delete(PaymentMethod)
def delete(self, cls):
_, count = cls.objects.all().delete()
self.stdout.write(self.style.WARNING(f"Successfully deleted {count} {cls}."))