add_publick_mark

This commit is contained in:
Dmitriy Kuzmenko 2019-12-05 17:19:38 +03:00
parent c62b4016f1
commit 73c66c7357
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,25 @@
from django.core.management.base import BaseCommand
from tqdm import tqdm
from product.models import Product
class Command(BaseCommand):
help = """Add public_mark to product from reviews."""
def handle(self, *args, **kwarg):
update_products = []
products = Product.objects.filter(
public_mark__isnull=True,
reviews__isnull=False).distinct()
for product in tqdm(products):
review = product.reviews.published().filter(
mark__isnull=False).order_by('-published_at').first()
if review:
product.public_mark = review.mark
update_products.append(product)
Product.objects.bulk_update(update_products, ['public_mark', ])
self.stdout.write(
self.style.WARNING(f'Updated products: {len(update_products)}'))

View File

@ -2,6 +2,7 @@
./manage.py transfer -a
./manage.py transfer -d
./manage.py transfer -e
./manage.py upd_transportation
./manage.py transfer --fill_city_gallery
./manage.py transfer -l
./manage.py transfer --product