mirror of
https://github.com/StefBuwalda/cal_counter.git
synced 2025-10-30 11:19:59 +00:00
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:
@@ -52,10 +52,16 @@ class FoodItem(db.Model):
|
||||
fat_100 = db.Column(db.Float, nullable=False)
|
||||
saturated_fat_100 = db.Column(db.Float)
|
||||
|
||||
food_logs = db.relationship("FoodLog", backref="food_item", lazy="dynamic")
|
||||
food_logs = db.relationship(
|
||||
"FoodLog",
|
||||
backref="food_item",
|
||||
lazy="dynamic",
|
||||
cascade="all, delete-orphan",
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
db.UniqueConstraint("barcode", "owner_id", name="barcode_owner_key"),
|
||||
db.UniqueConstraint("name", "owner_id", name="name_owner_key"),
|
||||
)
|
||||
|
||||
def __init__(
|
||||
|
||||
Reference in New Issue
Block a user