Squashed commit of the following:

commit 7fe30bfebf
Author: Stef <stbuwalda@gmail.com>
Date:   Mon Aug 11 14:32:53 2025 +0200

    Improve FoodItem uniqueness and add name constraint

    Refactored add_meal routes to check for existing FoodItems by name or barcode and improved form handling. Made barcode optional in FoodItemForm. Added a unique constraint on (name, owner_id) for FoodItem in both the model and database migrations, while retaining the (barcode, owner_id) constraint. Updated FoodItem relationship to cascade deletes.
This commit is contained in:
2025-08-11 14:33:13 +02:00
parent ad7f787ce5
commit 6ad7ffa62b
5 changed files with 134 additions and 46 deletions

View File

@@ -16,7 +16,7 @@ class LoginForm(FlaskForm):
class FoodItemForm(FlaskForm):
barcode = StringField("Barcode", validators=[InputRequired()])
barcode = StringField("Barcode", validators=[Optional()])
name = StringField("Product Name", validators=[DataRequired()])
energy = IntegerField("Energy per 100g", validators=[InputRequired()])
protein = FloatField("protein per 100g", validators=[InputRequired()])