From 9a16c4ae1704954e6e1c59e5c70c892121ba40b6 Mon Sep 17 00:00:00 2001 From: Husanjonazamov Date: Sat, 28 Mar 2026 19:34:40 +0500 Subject: [PATCH] category type boyciah filter to'g'rilandi --- .../api/management/commands/import_assets.py | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/core/apps/api/management/commands/import_assets.py b/core/apps/api/management/commands/import_assets.py index 151b8e0..b7c684f 100644 --- a/core/apps/api/management/commands/import_assets.py +++ b/core/apps/api/management/commands/import_assets.py @@ -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,22 +82,22 @@ 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) - - SubProductModel.objects.get_or_create( - product=product, - name=var_name, - defaults={'price': var_price if var_price > 0 else 0} - ) + if var_name and var_price: + SubProductModel.objects.get_or_create( + product=product, + name=var_name, + defaults={'price': var_price if var_price > 0 else 0} + ) def attach_image(self, instance, image_name, images_dir): if not image_name: