category type boyciah filter to'g'rilandi
This commit is contained in:
@@ -14,6 +14,10 @@ class Command(BaseCommand):
|
||||
def handle(self, *args, **options):
|
||||
base_dir = Path(settings.BASE_DIR)
|
||||
full_json_path = base_dir / 'assets' / 'menu_full.json'
|
||||
# If not in assets, check root (user's active doc was in root)
|
||||
if not full_json_path.exists():
|
||||
full_json_path = base_dir / 'menu_full.json'
|
||||
|
||||
images_dir = base_dir / 'assets' / 'images'
|
||||
|
||||
if not full_json_path.exists():
|
||||
@@ -38,13 +42,17 @@ class Command(BaseCommand):
|
||||
if section_slug.lower() == 'bar':
|
||||
cat_type = CategoryModel.CategoryType.BAR
|
||||
|
||||
# We need to distinguish sections in Category names if they share typeNames but are different entities
|
||||
# However, the type field on Category should handle separation.
|
||||
|
||||
for group in groups:
|
||||
type_name = group.get('typeName', 'General')
|
||||
|
||||
# USE ALL FIELDS IN TO BE UNIQUE: filial, name, type
|
||||
category, _ = CategoryModel.objects.get_or_create(
|
||||
filial=filial,
|
||||
name=type_name,
|
||||
defaults={'type': cat_type}
|
||||
type=cat_type
|
||||
)
|
||||
self.stdout.write(f" Category({cat_type}): {type_name}")
|
||||
|
||||
@@ -64,6 +72,9 @@ class Command(BaseCommand):
|
||||
price = prod_data.get('price', 0)
|
||||
image_name = prod_data.get('image')
|
||||
|
||||
# ID from JSON can help with uniqueness
|
||||
json_id = prod_data.get('id')
|
||||
|
||||
product, _ = ProductsModel.objects.get_or_create(
|
||||
subcategory=subcategory,
|
||||
name=prod_name,
|
||||
@@ -71,17 +82,17 @@ class Command(BaseCommand):
|
||||
)
|
||||
if image_name:
|
||||
self.attach_image(product, image_name, images_dir)
|
||||
# Attach first images if not set
|
||||
if i == 0:
|
||||
if not subcategory.image:
|
||||
self.attach_image(subcategory, image_name, images_dir)
|
||||
if not category.image:
|
||||
self.attach_image(category, image_name, images_dir)
|
||||
|
||||
# Subproducts (Variants)
|
||||
for var_data in prod_data.get('variants', []):
|
||||
var_name = var_data.get('name', 'Unnamed Variant')
|
||||
var_price = var_data.get('price', 0)
|
||||
|
||||
if var_name and var_price:
|
||||
SubProductModel.objects.get_or_create(
|
||||
product=product,
|
||||
name=var_name,
|
||||
|
||||
Reference in New Issue
Block a user