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:
parent
bf1668b35b
commit
8f5fd2582c
1 changed files with 3 additions and 2 deletions
|
|
@ -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…")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue