add bicolor

sync
Raz 8 months ago
parent 22b6d71169
commit 4be049db33
  1. 53
      shop/management/commands/create_initial_shop_data.py
  2. 18
      shop/migrations/0018_color_secondary_hex_color.py
  3. 2
      shop/models.py
  4. 6
      shop/static/shop/css/shop.css
  5. 8
      shop/templates/shop/partials/order_items_display.html
  6. 6
      shop/templates/shop/product_item.html
  7. 2
      shop/views.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'))

@ -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),
),
]

@ -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

@ -473,3 +473,9 @@ v .cart-table {
.cart-table tfoot td:empty {
display: none;
}
.color-sample,
.color-sample-cart {
position: relative;
overflow: hidden;
}

@ -5,7 +5,13 @@
<td class="text-left product-name" data-label="Produit">{{ item.product_title }}</td>
<td class="product-color" data-label="Couleur">
<div class="color-display">
<div class="color-sample-cart" style="background-color: {{ item.color_hex }}"></div>
<div class="color-sample-cart"
{% if item.secondary_color_hex %}
style="background-image: linear-gradient(to right, {{ item.color_hex }} 50%, {{ item.secondary_color_hex }} 50%);"
{% else %}
style="background-color: {{ item.color_hex }};"
{% endif %}
></div>
{{ item.color_name }} | {{ item.size_name }}
</div>
</td>

@ -19,7 +19,11 @@
<div class="color-samples">
{% for color in product.colors.all %}
<div class="color-sample {% if forloop.first %}selected{% endif %}"
style="background-color: {{ color.colorHex }}"
{% if color.secondary_hex_color %}
style="background-image: linear-gradient(to right, {{ color.colorHex }} 50%, {{ color.secondary_hex_color }} 50%);"
{% else %}
style="background-color: {{ color.colorHex }};"
{% endif %}
title="{{ color.name }}"
data-color-id="{{ color.id }}"
data-color-name="{{ color.name }}"

@ -421,6 +421,7 @@ def prepare_item_display_data(items, is_cart=True):
'product_title': item.product.title,
'color_name': item.color.name if item.color else 'N/A',
'color_hex': item.color.colorHex if item.color else '#FFFFFF',
'secondary_color_hex': item.color.secondary_hex_color if item.color and item.color.secondary_hex_color else None,
'size_name': item.size.name if item.size else 'N/A',
'quantity': item.quantity,
'total_price': item.get_total_price()
@ -433,6 +434,7 @@ def prepare_item_display_data(items, is_cart=True):
'product_title': item.product.title,
'color_name': item.color.name if item.color else 'N/A',
'color_hex': item.color.colorHex if item.color else '#FFFFFF',
'secondary_color_hex': item.color.secondary_hex_color if item.color and item.color.secondary_hex_color else None,
'size_name': item.size.name if item.size else 'N/A',
'quantity': item.quantity,
'total_price': item.get_total_price()

Loading…
Cancel
Save