|
|
|
|
@ -8,26 +8,38 @@ class Command(BaseCommand): |
|
|
|
|
def handle(self, *args, **kwargs): |
|
|
|
|
# Create colors |
|
|
|
|
self.stdout.write('Creating colors...') |
|
|
|
|
colors = { |
|
|
|
|
'Black': '#000000', |
|
|
|
|
'White': '#FFFFFF', |
|
|
|
|
'Red': '#FF0000', |
|
|
|
|
'Blue': '#0000FF', |
|
|
|
|
'Green': '#00FF00', |
|
|
|
|
'Yellow': '#FFFF00' |
|
|
|
|
} |
|
|
|
|
colors = [ |
|
|
|
|
{'name': 'Black', 'hex': '#000000', 'secondary_hex': None}, |
|
|
|
|
{'name': 'White', 'hex': '#FFFFFF', 'secondary_hex': None}, |
|
|
|
|
{'name': 'Red', 'hex': '#FF0000', 'secondary_hex': None}, |
|
|
|
|
{'name': 'Blue', 'hex': '#0000FF', 'secondary_hex': None}, |
|
|
|
|
{'name': 'Green', 'hex': '#00FF00', 'secondary_hex': None}, |
|
|
|
|
{'name': 'Yellow', 'hex': '#FFFF00', 'secondary_hex': None}, |
|
|
|
|
{'name': 'Black/White', 'hex': '#000000', 'secondary_hex': '#FFFFFF'}, |
|
|
|
|
{'name': 'Red/Blue', 'hex': '#FF0000', 'secondary_hex': '#0000FF'}, |
|
|
|
|
{'name': 'Green/Yellow', 'hex': '#00FF00', 'secondary_hex': '#FFFF00'} |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
color_objects = {} |
|
|
|
|
for name, hex_code in colors.items(): |
|
|
|
|
for color_data in colors: |
|
|
|
|
color, created = Color.objects.get_or_create( |
|
|
|
|
name=name, |
|
|
|
|
defaults={'colorHex': hex_code} |
|
|
|
|
name=color_data['name'], |
|
|
|
|
defaults={ |
|
|
|
|
'colorHex': color_data['hex'], |
|
|
|
|
'secondary_hex_color': color_data['secondary_hex'] |
|
|
|
|
} |
|
|
|
|
) |
|
|
|
|
color_objects[name] = color |
|
|
|
|
color_objects[color_data['name']] = color |
|
|
|
|
if created: |
|
|
|
|
self.stdout.write(f'Created color: {name}') |
|
|
|
|
self.stdout.write(f'Created color: {color_data["name"]}') |
|
|
|
|
else: |
|
|
|
|
self.stdout.write(f'Color already exists: {name}') |
|
|
|
|
# Update existing colors with secondary color if needed |
|
|
|
|
if color.secondary_hex_color != color_data['secondary_hex']: |
|
|
|
|
color.secondary_hex_color = color_data['secondary_hex'] |
|
|
|
|
color.save() |
|
|
|
|
self.stdout.write(f'Updated color: {color_data["name"]} with secondary color') |
|
|
|
|
else: |
|
|
|
|
self.stdout.write(f'Color already exists: {color_data["name"]}') |
|
|
|
|
|
|
|
|
|
# Create sizes |
|
|
|
|
self.stdout.write('Creating sizes...') |
|
|
|
|
@ -50,7 +62,7 @@ class Command(BaseCommand): |
|
|
|
|
'price': 99.99, |
|
|
|
|
'ordering_value': 1, |
|
|
|
|
'cut': 2, # Men |
|
|
|
|
'colors': ['Black', 'White', 'Red'], |
|
|
|
|
'colors': ['Black', 'White', 'Red', 'Black/White'], |
|
|
|
|
'sizes': ['M', 'L', 'XL'], |
|
|
|
|
'image_filename': 'hat.jpg' # Just the filename |
|
|
|
|
}, |
|
|
|
|
@ -59,7 +71,7 @@ class Command(BaseCommand): |
|
|
|
|
'price': 29.99, |
|
|
|
|
'ordering_value': 2, |
|
|
|
|
'cut': 1, # Women |
|
|
|
|
'colors': ['Black', 'White', 'Blue', 'Red'], |
|
|
|
|
'colors': ['Black', 'White', 'Blue', 'Red', 'Red/Blue'], |
|
|
|
|
'sizes': ['XS', 'S', 'M', 'L', 'XL'], |
|
|
|
|
'image_filename': 'tshirt.jpg' # Just the filename |
|
|
|
|
}, |
|
|
|
|
@ -68,7 +80,7 @@ class Command(BaseCommand): |
|
|
|
|
'price': 19.99, |
|
|
|
|
'ordering_value': 3, |
|
|
|
|
'cut': 3, # Kids |
|
|
|
|
'colors': ['Blue', 'White'], |
|
|
|
|
'colors': ['Blue', 'White', 'Green/Yellow'], |
|
|
|
|
'sizes': ['XS', 'S', 'M'], |
|
|
|
|
'image_filename': 'kids_shorts.jpg' # Just the filename |
|
|
|
|
} |
|
|
|
|
@ -109,4 +121,11 @@ class Command(BaseCommand): |
|
|
|
|
else: |
|
|
|
|
self.stdout.write(f'Product already exists: {product_data["title"]}') |
|
|
|
|
|
|
|
|
|
# Update existing products with new colors if needed |
|
|
|
|
existing_colors = set(product.colors.all().values_list('name', flat=True)) |
|
|
|
|
for color_name in product_data['colors']: |
|
|
|
|
if color_name not in existing_colors: |
|
|
|
|
product.colors.add(color_objects[color_name]) |
|
|
|
|
self.stdout.write(f'Added color {color_name} to existing product: {product_data["title"]}') |
|
|
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('Successfully created initial shop data')) |
|
|
|
|
|