Add admin check and update FoodItems model

Introduced an admin_required check for all admin routes using Flask-Login's current_user. Updated the FoodItems model to use per-100g nutritional fields and removed unit relationships. Seed script now creates both admin and regular user accounts.
This commit is contained in:
2025-06-27 17:23:54 +02:00
parent 1b428b0bda
commit a5312d7ad0
3 changed files with 28 additions and 15 deletions

View File

@@ -1,4 +1,6 @@
from flask import Blueprint, render_template
from flask import Blueprint, render_template, abort
from flask_login import current_user
from models import FoodItems
admin_bp = Blueprint(
"admin",
@@ -8,6 +10,13 @@ admin_bp = Blueprint(
)
@admin_bp.before_request
def admin_required():
if not current_user.is_admin:
abort(403)
@admin_bp.route("/food_items", methods=["GET"])
def food_items():
return render_template("food_items.html")
items = FoodItems.query.all()
return render_template("food_items.html", items=items)