Added tag
This commit is contained in:
parent
1b63206a80
commit
923da074a6
Binary file not shown.
@ -5,4 +5,5 @@ from wtforms.validators import InputRequired
|
||||
class UserForm(FlaskForm):
|
||||
title = StringField('title', validators=[InputRequired()])
|
||||
author = StringField('author', validators=[InputRequired()])
|
||||
tag = StringField('tag', validators=[InputRequired()])
|
||||
file = FileField()
|
||||
|
@ -6,12 +6,14 @@ class Book(db.Model):
|
||||
title = db.Column(db.String(255))
|
||||
author = db.Column(db.String(255))
|
||||
file = db.Column(db.String(255))
|
||||
tag = db.Column(db.String(255))
|
||||
|
||||
|
||||
def __init__(self, title, author, file):
|
||||
def __init__(self, title, author, file, tag):
|
||||
self.title = title
|
||||
self.author = author
|
||||
self.file = file
|
||||
self.tag = tag
|
||||
|
||||
def __repr__(self):
|
||||
return '<Title %r>' % self.title
|
||||
@ -22,7 +24,8 @@ class BookSchema(Schema):
|
||||
title = fields.Str()
|
||||
author = fields.Str()
|
||||
file = fields.Str()
|
||||
tag = fields.Str()
|
||||
|
||||
def must_not_be_blank(data):
|
||||
if not data:
|
||||
raise ValidationError('Data not provided.')
|
||||
raise ValidationError('You forgot to write stuff.')
|
||||
|
@ -18,6 +18,8 @@
|
||||
{{ form.csrf_token }}
|
||||
<div class="form-group">{{ form.title.label }} {{ form.title(size=20, class="form-control") }}</div>
|
||||
<div class="form-group">{{ form.author.label }} {{ form.author(size=20, class="form-control") }}</div>
|
||||
<div class="form-group">{{ form.tag.label }} {{ form.tag(size=20, class="form-control") }}</div>
|
||||
|
||||
{{ form.file }}
|
||||
<button type="submit" class="btn btn-primary">Upload</button>
|
||||
</form>
|
||||
|
@ -19,11 +19,13 @@
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Author</th>
|
||||
<th>Tag</th>
|
||||
</tr>
|
||||
{% for book in books %}
|
||||
<tr>
|
||||
<td><a href="books/{{ book.id }}">{{ book.title }}</a></td>
|
||||
<td>{{ book.author }}</td>
|
||||
<td>{{ book.tag}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
@ -82,8 +82,9 @@ def add_book():
|
||||
|
||||
title = user_form.title.data # You could also have used request.form['name']
|
||||
author = user_form.author.data # You could also have used request.form['email']
|
||||
tag = user_form.tag.data
|
||||
# save user to database
|
||||
book = Book(title, author, filename)
|
||||
book = Book(title, author, filename, tag)
|
||||
db.session.add(book)
|
||||
db.session.commit()
|
||||
flash("%s added to the library" % (title))
|
||||
|
Loading…
Reference in New Issue
Block a user