zapytanie sql
This commit is contained in:
15
app.py
15
app.py
@@ -182,7 +182,7 @@ class Item(db.Model):
|
||||
added_at = db.Column(db.DateTime, default=utcnow)
|
||||
added_by = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=True)
|
||||
added_by_user = db.relationship(
|
||||
"User", backref="added_items", lazy=True, foreign_keys=[added_by]
|
||||
"User", backref="added_items", lazy="joined", foreign_keys=[added_by]
|
||||
)
|
||||
|
||||
purchased = db.Column(db.Boolean, default=False)
|
||||
@@ -1195,6 +1195,13 @@ def view_list(list_id):
|
||||
percent = (purchased_count / total_count * 100) if total_count > 0 else 0
|
||||
is_owner = current_user.id == shopping_list.owner_id
|
||||
|
||||
for item in items:
|
||||
if item.added_by_id != item.owner_id:
|
||||
item.added_by = item.added_by_user.username if item.added_by_user else "?"
|
||||
else:
|
||||
item.added_by = None
|
||||
|
||||
|
||||
return render_template(
|
||||
"list.html",
|
||||
list=shopping_list,
|
||||
@@ -1322,6 +1329,12 @@ def shared_list(token=None, list_id=None):
|
||||
list_id
|
||||
)
|
||||
|
||||
for item in items:
|
||||
if item.added_by_id != item.owner_id:
|
||||
item.added_by = item.added_by_user.username if item.added_by_user else "?"
|
||||
else:
|
||||
item.added_by = None
|
||||
|
||||
return render_template(
|
||||
"list_share.html",
|
||||
list=shopping_list,
|
||||
|
Reference in New Issue
Block a user