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):
|
||||
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 #######################################
|
||||
|
||||
@@ -44,36 +44,42 @@
|
||||
</tbody>
|
||||
</table>
|
||||
{% else %}
|
||||
<h3>View/Edit Book</h1>
|
||||
{% set keys = [ 'title', 'author', 'publisher', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||
<h3><center>View/Edit Book</center></h1>
|
||||
{% set keys = [ 'title', 'author', 'publisher', 'genre', 'owned', 'covertype', 'condition', 'year_published', 'rating', 'notes', 'blurb' ] %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<form class="form">
|
||||
<div class="row with-margin">
|
||||
<form class="form col-lg-12">
|
||||
{% for key in keys %}
|
||||
<div class="form-group row">
|
||||
<label for="{{key}}" class="col-sm-4 col-form-label">{{key}}:</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group input-group-lg">
|
||||
<label for="{{key}}" class="col-lg-2 col-form-label">{{key}}:</label>
|
||||
<div class="col-lg-10">
|
||||
{% if books[key] is iterable and books[key] is not string %}
|
||||
<table>
|
||||
{% for objects in books[key] %}
|
||||
<tr>
|
||||
{% for attr in objects %}
|
||||
<label for="{{attr}}" class="col-sm-4 col-form-label">{{attr}}:</label>
|
||||
<input type="text" class="form-control" id="not-sure-{{key}}-{{attr}}" value="{{objects[attr]}}">
|
||||
{% if attr != "id" %}
|
||||
<td>
|
||||
<input type="text" class="form-control input-lg" id="not-sure-{{key}}-{{attr}}" value="{{objects[attr]}}">
|
||||
</td>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
</div>
|
||||
</div class="col-lg-8">
|
||||
</div class="form-group">
|
||||
{% endfor %}
|
||||
</form>
|
||||
</div class="row">
|
||||
</div class="container">
|
||||
{{books.genre}}
|
||||
{% if books.sub_book is defined %}
|
||||
<p>sub_book is defined: {{books.sub_book}}</p>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user