add_publick_mark
This commit is contained in:
parent
c62b4016f1
commit
73c66c7357
25
apps/product/management/commands/add_public_mark.py
Normal file
25
apps/product/management/commands/add_public_mark.py
Normal 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)}'))
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
./manage.py transfer -a
|
./manage.py transfer -a
|
||||||
./manage.py transfer -d
|
./manage.py transfer -d
|
||||||
./manage.py transfer -e
|
./manage.py transfer -e
|
||||||
|
./manage.py upd_transportation
|
||||||
./manage.py transfer --fill_city_gallery
|
./manage.py transfer --fill_city_gallery
|
||||||
./manage.py transfer -l
|
./manage.py transfer -l
|
||||||
./manage.py transfer --product
|
./manage.py transfer --product
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user