Features: 1) Add deletion of related AttributeValue and ProductImage records when deleting never ordered products.

Fixes: None;

Extra: Remove redundant blank line for cleanup.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-07-05 01:48:58 +03:00
parent bf1668b35b
commit 8f5fd2582c

View file

@ -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…")