From 03be396c873eac1a0fd035e765f350f2b10e161e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=BCller?= Date: Fri, 3 Nov 2017 17:38:48 +0100 Subject: [PATCH] Change SQL query to get already set tags --- soundboard.py | 20 +++++++++++++++++++- templates/edit.html | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/soundboard.py b/soundboard.py index cc0da8a..f104b1b 100644 --- a/soundboard.py +++ b/soundboard.py @@ -94,6 +94,24 @@ def edit(sound): # TODO: Store changes return redirect("/edit") - tags = queryDB("SELECT name FROM tag ORDER BY name COLLATE NOCASE") + tags = queryDB("""\ +SELECT + tag.name, + checked.id IS NOT NULL AS checked +FROM + tag +LEFT OUTER JOIN ( + SELECT + tag.id + FROM + tag + JOIN + button_tags + ON + fk_tag = tag.id + WHERE fk_button = 1 +) AS checked +ON tag.id = checked.id""") + print(tags) return render_template("edit.html", sound=sound, tags=tags) diff --git a/templates/edit.html b/templates/edit.html index d9182ad..2c4ceb7 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -8,7 +8,7 @@