diff --git a/core/management/commands/delete_never_ordered_products.py b/core/management/commands/delete_never_ordered_products.py index 885eddb3..c8bd762e 100644 --- a/core/management/commands/delete_never_ordered_products.py +++ b/core/management/commands/delete_never_ordered_products.py @@ -1,11 +1,10 @@ from django.core.management.base import BaseCommand from django.db import transaction -from core.models import Product +from core.models import AttributeValue, Product, ProductImage CHUNK_SIZE = 5000 - class Command(BaseCommand): help = "Delete Product rows with no OrderProduct, in batches" @@ -17,6 +16,8 @@ class Command(BaseCommand): if not batch_ids: break with transaction.atomic(): + AttributeValue.objects.filter(product_id__in=batch_ids).delete() + ProductImage.objects.filter(product_id__in=batch_ids).delete() Product.objects.filter(pk__in=batch_ids).delete() self.stdout.write(f"Deleted {len(batch_ids)} products…")