From e31e93797452f849e632a47274d4fbabaeed79ba Mon Sep 17 00:00:00 2001 From: Raz Date: Fri, 21 Mar 2025 15:30:00 +0100 Subject: [PATCH] fix bug --- .../commands/create_initial_shop_data.py | 16 ++++++++-------- shop/models.py | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/shop/management/commands/create_initial_shop_data.py b/shop/management/commands/create_initial_shop_data.py index b448420..a613712 100644 --- a/shop/management/commands/create_initial_shop_data.py +++ b/shop/management/commands/create_initial_shop_data.py @@ -45,7 +45,7 @@ class Command(BaseCommand): # Create sizes self.stdout.write('Creating sizes...') - sizes = ['XS', 'S', 'M', 'L', 'XL', 'XXL', '3XL', '4XL'] + sizes = ['Taille Unique', 'XS', 'S', 'M', 'L', 'XL', 'XXL', '3XL', '4XL'] size_objects = {} for name in sizes: @@ -67,7 +67,7 @@ class Command(BaseCommand): 'ordering_value': 1, 'cut': 0, # Unisex 'colors': ['Blanc', 'Bleu Sport', 'Noir'], - 'sizes': [], + 'sizes': ['Taille Unique'], 'image_filename': 'hat.jpg' }, { @@ -75,7 +75,7 @@ class Command(BaseCommand): 'title': 'Padel Club Hoodie Femme', 'description': 'Hoodie femme logo cœur et dos', 'price': 50.00, - 'ordering_value': 1, + 'ordering_value': 10, 'cut': 1, 'colors': ['Blanc', 'Bleu Sport', 'Noir', 'Fuchsia'], 'sizes': ['XS', 'S', 'M', 'L', 'XL', 'XXL'], @@ -86,7 +86,7 @@ class Command(BaseCommand): 'title': 'Padel Club Hoodie Homme', 'description': 'Hoodie homme logo cœur et dos', 'price': 50.00, - 'ordering_value': 2, + 'ordering_value': 11, 'cut': 2, 'colors': ['Blanc', 'Bleu Sport', 'Noir', 'Fuchsia'], 'sizes': ['XS', 'S', 'M', 'L', 'XL', 'XXL', '3XL', '4XL'], @@ -97,7 +97,7 @@ class Command(BaseCommand): 'title': 'Débardeur Femme', 'description': 'Débardeur femme avec logo coeur.', 'price': 25.00, - 'ordering_value': 2, + 'ordering_value': 20, 'cut': 1, # Women 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], 'sizes': ['XS', 'S', 'M', 'L', 'XL'], @@ -108,7 +108,7 @@ class Command(BaseCommand): 'title': 'Jupe bicolore Femme', 'description': 'Avec short intégré logo jambe (sauf corail)', 'price': 30.00, - 'ordering_value': 3, + 'ordering_value': 30, 'cut': 1, # Women 'colors': ['Blanc / Bleu Sport', 'Bleu Sport / Blanc', 'Corail / Noir', 'Noir / Gris Foncé Chiné'], 'sizes': ['XS', 'S', 'M', 'L', 'XL'], @@ -119,7 +119,7 @@ class Command(BaseCommand): 'title': 'T-shirt Bicolore Homme', 'description': 'T-shirt bicolore avec logo coeur.', 'price': 25.00, - 'ordering_value': 1, + 'ordering_value': 40, 'cut': 2, # Men 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], 'sizes': ['S', 'M', 'L', 'XL', 'XXL', '3XL'], @@ -130,7 +130,7 @@ class Command(BaseCommand): 'title': 'Short Bicolore Homme', 'description': 'Short bicolore avec logo jambe.', 'price': 30.00, - 'ordering_value': 3, + 'ordering_value': 50, 'cut': 2, # Men 'colors': ['Blanc / Bleu Sport', 'Noir', 'Noir / Gris Foncé Chiné'], 'sizes': ['S', 'M', 'L', 'XL', 'XXL', '3XL'], diff --git a/shop/models.py b/shop/models.py index 175a324..508483e 100644 --- a/shop/models.py +++ b/shop/models.py @@ -56,6 +56,9 @@ class CartItem(models.Model): session_id = models.CharField(max_length=255, null=True, blank=True) date_added = models.DateTimeField(auto_now_add=True) + class Meta: + ordering = ['product__ordering_value', 'product__cut'] # Sort by product's ordering_value + def __str__(self): return f"{self.quantity} x {self.product.title}" @@ -100,6 +103,9 @@ class OrderItem(models.Model): size = models.ForeignKey(Size, on_delete=models.SET_NULL, null=True, blank=True) price = models.DecimalField(max_digits=10, decimal_places=2) + class Meta: + ordering = ['product__ordering_value', 'product__cut'] # Sort by product's ordering_value + def __str__(self): return f"{self.quantity} x {self.product.title}"