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
This commit is contained in:
6
main.py
6
main.py
@@ -91,16 +91,14 @@ class Genre_LstSchema(ma.SQLAlchemyAutoSchema):
|
|||||||
|
|
||||||
class BookSchema(ma.SQLAlchemyAutoSchema):
|
class BookSchema(ma.SQLAlchemyAutoSchema):
|
||||||
author = ma.Nested(AuthorSchema, many=True)
|
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:
|
class Meta:
|
||||||
model = Book
|
model = Book
|
||||||
include_relationships = True
|
include_relationships = True
|
||||||
load_instance = True
|
load_instance = True
|
||||||
|
|
||||||
### DDP: do I need many=True on Author as books have many authors? (or in BookSchema declaration above?)
|
### 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()
|
book_schema = BookSchema()
|
||||||
|
|
||||||
####################################### ROUTES #######################################
|
####################################### ROUTES #######################################
|
||||||
|
|||||||
@@ -44,36 +44,42 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
<h3>View/Edit Book</h1>
|
<h3><center>View/Edit Book</center></h1>
|
||||||
{% set keys = [ 'title', 'author', 'publisher', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row with-margin">
|
||||||
<form class="form">
|
<form class="form col-lg-12">
|
||||||
{% for key in keys %}
|
{% for key in keys %}
|
||||||
<div class="form-group row">
|
<div class="input-group input-group-lg">
|
||||||
<label for="{{key}}" class="col-sm-4 col-form-label">{{key}}:</label>
|
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
|
||||||
<div class="col-sm-8">
|
<div class="col-lg-10">
|
||||||
{% if books[key] is iterable and books[key] is not string %}
|
{% if books[key] is iterable and books[key] is not string %}
|
||||||
|
<table>
|
||||||
{% for objects in books[key] %}
|
{% for objects in books[key] %}
|
||||||
|
<tr>
|
||||||
{% for attr in objects %}
|
{% for attr in objects %}
|
||||||
<label for="{{attr}}" class="col-sm-4 col-form-label">{{attr}}:</label>
|
{% if attr != "id" %}
|
||||||
<input type="text" class="form-control" id="not-sure-{{key}}-{{attr}}" value="{{objects[attr]}}">
|
<td>
|
||||||
|
<input type="text" class="form-control input-lg" id="not-sure-{{key}}-{{attr}}" value="{{objects[attr]}}">
|
||||||
|
</td>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</table>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if key == "notes" or key == "blurb" %}
|
{% if key == "notes" or key == "blurb" %}
|
||||||
<textarea rows="10" type="text" class="form-control" id="{{key}}">{{books[key]}}</textarea>
|
<textarea rows="5" type="text" class="form-control input-lg" id="{{key}}">{{books[key]}}</textarea>
|
||||||
{% else %}
|
{% else %}
|
||||||
<input type="text" class="form-control" id="{{key}}" value="{{books[key]}}">
|
<input type="text" class="form-control input-lg" id="{{key}}" value="{{books[key]}}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div class="col-lg-8">
|
||||||
</div class="form-group">
|
</div class="form-group">
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</form>
|
</form>
|
||||||
</div class="row">
|
</div class="row">
|
||||||
</div class="container">
|
</div class="container">
|
||||||
{{books.genre}}
|
|
||||||
{% if books.sub_book is defined %}
|
{% if books.sub_book is defined %}
|
||||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user