Skip to content

Commit

Permalink
Merge main into release (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkachel committed Jan 23, 2025
1 parent 87f732e commit c23c258
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions system_meta/management/commands/update_product_image_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from django.core.management.base import BaseCommand

from system_meta.models import Product
from system_meta.tasks import update_products


class Command(BaseCommand):
"""
A management command to update image_metadata for all Product objects
Example usage: python manage.py update_product_image_data --product_id 1
"""

help = "Update image_metadata for all Product objects"

def add_arguments(self, parser):
parser.add_argument(
"--product-id",
type=int,
help="The ID of the product to update",
)
parser.add_argument(
"--sku",
type=str,
help="The SKU of the product to update",
)
parser.add_argument(
"--name",
type=str,
help="The name of the product to update",
)
parser.add_argument(
"--system-name",
type=str,
help="The system name of the product to update",
)

def handle(self, *args, **kwargs): # noqa: ARG002
product_id = kwargs.get("product_id")
sku = kwargs.get("sku")
name = kwargs.get("name")
system_name = kwargs.get("system_name")

if product_id:
products = Product.objects.filter(id=product_id)
elif sku:
products = Product.objects.filter(sku=sku, system__name=system_name)
elif name:
products = Product.objects.filter(name=name)
else:
products = Product.objects.all()

for product in products:
update_products.delay(product.id)
self.stdout.write(
self.style.SUCCESS(
f"Successfully updated image metadata for product {product.id}"
)
)

0 comments on commit c23c258

Please sign in to comment.