fixed backend python error

This commit is contained in:
nvrl committed 2026-02-16 19:16:47 +01:00
1 parent 5c2366a7c7
commit f4edf65c22
3 files changed
+31 -5

No files matched your search

@@ -126,9 +126,7 @@ class Command(BaseCommand):
flavor = Flavor.objects.filter(name=title, category=category, is_legacy=False).first()
if not flavor:
# One last check: if name exists in DIFFERENT category, we still create a new one
# If name exists in SAME category, we would have found it above.
flavor = Flavor(external_id=p['id'], name=title, is_legacy=False)
flavor = Flavor(external_id=p['id'], name=title, category=category, is_legacy=False)
created_count += 1
else:
updated_count += 1
@@ -0,0 +1,22 @@
# Generated by Django 6.0.2 on 2026-02-16 18:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0010_user_avatar'),
]
operations = [
migrations.AlterField(
model_name='flavor',
name='name',
field=models.CharField(max_length=100),
),
migrations.AddConstraint(
model_name='flavor',
constraint=models.UniqueConstraint(fields=('name', 'category'), name='unique_flavor_name_per_category'),
),
]
+8 -2
View File
@@ -54,7 +54,7 @@ class Category(models.Model):
class Flavor(models.Model):
category = models.ForeignKey(Category, related_name='flavors', on_delete=models.CASCADE)
name = models.CharField(max_length=100, unique=True)
name = models.CharField(max_length=100) # Removed unique=True here
description = models.TextField(blank=True)
image_url = models.URLField(max_length=1000, blank=True, null=True)
image = models.ImageField(upload_to='flavors/', blank=True, null=True)
@@ -64,8 +64,14 @@ class Flavor(models.Model):
external_id = models.BigIntegerField(unique=True, null=True, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
# This allows "Erdbeere" in Iced Tea and "Erdbeere" in Milkshake
constraints = [
models.UniqueConstraint(fields=['name', 'category'], name='unique_flavor_name_per_category')
]
def __str__(self):
return self.name
return f"{self.name} ({self.category.name})"
@property
def get_average_rating(self):