From a57d68ecfa024d1b5577b9a1df93509f0ffd2350 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 8 Nov 2020 15:46:59 +1100 Subject: [PATCH] made genre use the schemas properly to return actual joined data, not just genre_id. Also made author/publisher/genre all use many=True, while that is nto true for publisher, it makes the jinja code consisten -- Might need to fix this one day if the writing to the database is somehow more automatic and needs it to be an actual one-to-many, not a many-to-many --- main.py | 6 ++---- templates/books.html | 32 +++++++++++++++++++------------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/main.py b/main.py index 192cd02..005010d 100644 --- a/main.py +++ b/main.py @@ -91,16 +91,14 @@ class Genre_LstSchema(ma.SQLAlchemyAutoSchema): class BookSchema(ma.SQLAlchemyAutoSchema): author = ma.Nested(AuthorSchema, many=True) - publisher = ma.Nested(PublisherSchema) + publisher = ma.Nested(PublisherSchema, many=True) + genre = ma.Nested(Genre_LstSchema, many=True) class Meta: model = Book include_relationships = True load_instance = True ### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?) -author_schema = AuthorSchema(many=True) -publisher_schema = PublisherSchema() -genre_schema = Genre_LstSchema(many=True) book_schema = BookSchema() ####################################### ROUTES ####################################### diff --git a/templates/books.html b/templates/books.html index e166e61..9af902f 100644 --- a/templates/books.html +++ b/templates/books.html @@ -44,36 +44,42 @@ {% else %} -

View/Edit Book

- {% set keys = [ 'title', 'author', 'publisher', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %} +

View/Edit Book

+ {% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
-
-
+
+ {% for key in keys %} -
- -
+
+ +
{% if books[key] is iterable and books[key] is not string %} + {% for objects in books[key] %} + {% for attr in objects %} - - + {% if attr != "id" %} + + {% endif %} {% endfor %} + {% endfor %} +
+ +
{% else %} {% if key == "notes" or key == "blurb" %} - + {% else %} - + {% endif %} {% endif %} -
+
{% endfor %}
- {{books.genre}} {% if books.sub_book is defined %}

sub_book is defined: {{books.sub_book}}

{% endif %}