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