From 9610915b1926984d6feb6538402f48e1c38fb022 Mon Sep 17 00:00:00 2001 From: eclipse Date: Thu, 8 May 2025 09:47:20 +0200 Subject: [PATCH] Genres can now be added, changed, and removed to/from Werk entries --- the_works/models.py | 6 +- the_works/templates/views/werk.html | 7 +- the_works/templates/views/werk_detail.html | 76 +++++++++++++--------- the_works/views/werk.py | 29 +++++++-- 4 files changed, 77 insertions(+), 41 deletions(-) diff --git a/the_works/models.py b/the_works/models.py index e05ac0b..a559f04 100644 --- a/the_works/models.py +++ b/the_works/models.py @@ -17,7 +17,8 @@ class Werk(db.Model): verlag = relationship("Verlag", back_populates="werk") werksform = relationship("Werksform", back_populates="werk") veroeffentlichung = relationship("Veroeffentlichung", back_populates="werk") - werk_genre = relationship("Werk_Genre", back_populates="werk") + werk_genre = relationship("Werk_Genre", back_populates="werk", cascade="save-update, merge, delete, delete-orphan") + genres = association_proxy("werk_genre", "Genre") class Veroeffentlichung(db.Model): __table__ = db.Model.metadata.tables['Veroeffentlichung'] @@ -73,3 +74,6 @@ class Werk_Genre(db.Model): werk = relationship("Werk", back_populates="werk_genre") genre = relationship("Genre", back_populates="werk_genre") + def __init__(self, genre: int): + self.Genre = genre + diff --git a/the_works/templates/views/werk.html b/the_works/templates/views/werk.html index c1d1362..5ea6b89 100644 --- a/the_works/templates/views/werk.html +++ b/the_works/templates/views/werk.html @@ -1,4 +1,5 @@ {% extends 'base.html' %} +{% set SPLIT_CHARACTER = ", " %} {% block title %}Werke{% endblock title %} @@ -12,7 +13,7 @@ }); deRole("#werk-table"); - // create "New"-button and append it to the
containing the DataTables search field + // create "New"-element and append it to the
containing the DataTables search field let a = document.createElement("a"); a.id = "create-button"; a.setAttribute("title", "Werk hinzufügen"); @@ -38,6 +39,7 @@ Reihe Verlag Werksform + Genre(s) Aktionen @@ -49,10 +51,11 @@ {{ werk["Reihe"] }} {{ werk["Verlag"] }} {{ werk["Werksform"] }} + {{ werk["Genre_list"] | join(SPLIT_CHARACTER) }} {% endfor %} -{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/the_works/templates/views/werk_detail.html b/the_works/templates/views/werk_detail.html index 54c4483..e4b95c3 100644 --- a/the_works/templates/views/werk_detail.html +++ b/the_works/templates/views/werk_detail.html @@ -47,12 +47,15 @@ Werk bearbeiten {% block content %}
-
+
+ +
+
+
- -
- - -
-
-
+
+
+ +
-
-
+ +
+
+
+ Genre(s) + {% for g in genres %} + + + {% endfor %} +
+
+
+
-
-
+ +
+
-
+ +