xavfsizlik taminlandi
This commit is contained in:
@@ -28,46 +28,37 @@ class Command(BaseCommand):
|
||||
full_data = json.load(f)
|
||||
|
||||
# 1. Process Hierarchy
|
||||
# Root is a dict of filials: {"karomat": {...}, "qoratosh": {...}}
|
||||
for filial_slug, sections in full_data.items():
|
||||
filial_name = filial_slug.capitalize()
|
||||
self.stdout.write(self.style.SUCCESS(f"Processing Filial: {filial_name}"))
|
||||
filial, _ = FilialModel.objects.get_or_create(name=filial_name)
|
||||
|
||||
# Sections are "restoran" and "bar"
|
||||
for section_slug, groups in sections.items():
|
||||
cat_name = section_slug.capitalize() # "Restoran" or "Bar"
|
||||
cat_type = CategoryModel.CategoryType.RESTAURANT
|
||||
if section_slug.lower() == 'bar':
|
||||
cat_type = CategoryModel.CategoryType.BAR
|
||||
|
||||
category, _ = CategoryModel.objects.get_or_create(
|
||||
filial=filial,
|
||||
name=cat_name,
|
||||
defaults={'type': cat_type}
|
||||
)
|
||||
self.stdout.write(f" Category({cat_type}): {cat_name}")
|
||||
|
||||
# Groups are items in the list (e.g. Salads, Soups)
|
||||
for group in groups:
|
||||
type_name = group.get('typeName', 'General')
|
||||
|
||||
# group has "subCategories"
|
||||
category, _ = CategoryModel.objects.get_or_create(
|
||||
filial=filial,
|
||||
name=type_name,
|
||||
defaults={'type': cat_type}
|
||||
)
|
||||
self.stdout.write(f" Category({cat_type}): {type_name}")
|
||||
|
||||
for subcat_data in group.get('subCategories', []):
|
||||
subcat_name = subcat_data.get('name', 'General')
|
||||
|
||||
# Use group's type_name if subcat_name is a placeholder (starts with '(')
|
||||
if subcat_name.startswith('('):
|
||||
subcat_name = type_name
|
||||
|
||||
subcategory, created = SubcategoryModel.objects.get_or_create(
|
||||
subcategory, _ = SubcategoryModel.objects.get_or_create(
|
||||
category=category,
|
||||
name=subcat_name
|
||||
)
|
||||
|
||||
self.stdout.write(f" Subcategory: {subcat_name}")
|
||||
|
||||
# Products
|
||||
for i, prod_data in enumerate(subcat_data.get('products', [])):
|
||||
prod_name = prod_data.get('name', 'Unnamed Product')
|
||||
price = prod_data.get('price', 0)
|
||||
@@ -80,11 +71,13 @@ class Command(BaseCommand):
|
||||
)
|
||||
if image_name:
|
||||
self.attach_image(product, image_name, images_dir)
|
||||
# Attach first product's image to the subcategory if it hasn't one
|
||||
if i == 0 and not subcategory.image:
|
||||
# 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)
|
||||
|
||||
Reference in New Issue
Block a user