diff --git a/shop/management/commands/create_initial_shop_data.py b/shop/management/commands/create_initial_shop_data.py index eb4438f..92fc353 100644 --- a/shop/management/commands/create_initial_shop_data.py +++ b/shop/management/commands/create_initial_shop_data.py @@ -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')) diff --git a/shop/migrations/0018_color_secondary_hex_color.py b/shop/migrations/0018_color_secondary_hex_color.py new file mode 100644 index 0000000..d1df904 --- /dev/null +++ b/shop/migrations/0018_color_secondary_hex_color.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.11 on 2025-03-21 12:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('shop', '0017_order_stripe_mode'), + ] + + operations = [ + migrations.AddField( + model_name='color', + name='secondary_hex_color', + field=models.CharField(blank=True, help_text='Secondary color in hex format for split color display', max_length=7, null=True), + ), + ] diff --git a/shop/models.py b/shop/models.py index e0cd3a2..73008b2 100644 --- a/shop/models.py +++ b/shop/models.py @@ -16,6 +16,8 @@ class CutChoices(models.IntegerChoices): class Color(models.Model): name = models.CharField(max_length=20, unique=True) colorHex = models.CharField(max_length=7, default="#FFFFFF", help_text="Color in hex format (e.g. #FF0000)") + secondary_hex_color = models.CharField(max_length=7, null=True, blank=True, + help_text="Secondary color in hex format for split color display") def __str__(self): return self.name diff --git a/shop/static/shop/css/shop.css b/shop/static/shop/css/shop.css index af235ff..2cc272d 100644 --- a/shop/static/shop/css/shop.css +++ b/shop/static/shop/css/shop.css @@ -473,3 +473,9 @@ v .cart-table { .cart-table tfoot td:empty { display: none; } + +.color-sample, +.color-sample-cart { + position: relative; + overflow: hidden; +} diff --git a/shop/templates/shop/partials/order_items_display.html b/shop/templates/shop/partials/order_items_display.html index 1dd70a7..d86045f 100644 --- a/shop/templates/shop/partials/order_items_display.html +++ b/shop/templates/shop/partials/order_items_display.html @@ -5,7 +5,13 @@ {{ item.product_title }}
-
+
{{ item.color_name }} | {{ item.size_name }}
diff --git a/shop/templates/shop/product_item.html b/shop/templates/shop/product_item.html index dda68f4..ceac6c3 100644 --- a/shop/templates/shop/product_item.html +++ b/shop/templates/shop/product_item.html @@ -19,7 +19,11 @@
{% for color in product.colors.all %}