Commit 753b82be authored by Colleen's avatar Colleen

Added forms and additional templates

parent 8854da00
from django import forms
from .models import Author, Books
class AuthorForm(forms.Form):
class Meta:
model = Author
fields = ['first_name','last_name','age','nationality','bio']
class BooksForm(forms.Form):
class Meta:
model = Books
fields = ['title','author','publisher','year_published','ISBN','blurb']
\ No newline at end of file
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form action="/add_author" method="post">
{% csrf_token %}
{{ form }}
First Name: <input type="text" name="title"/><br>
Last Name: <input type="text" name="author"/><br>
Age: <input type="text" name="publisher"/><br>
Nationality: <input type="text" name="year_published"/><br>
Bio: <input type="text" name="ISBN"/><p>
<input type="submit" value="Add Book"/>
</form>
{% endblock %}
\ No newline at end of file
{% block content %}
{{ form.non_field_errors }}
{% for field in form %}
{% if field.errors %}
<p>{{ field.label }} has the following errors:</p>
<ul>
{% for error in field.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
{% endfor %}
<form action="/add_book" method="post">
{% csrf_token %}
{{ form }}
Title: <input type="text" name="title"/><br>
Author: <input type="text" name="author"/><br>
Publisher: <input type="text" name="publisher"/><br>
Year Published: <input type="text" name="year_published"/><br>
ISBN: <input type="text" name="ISBN"/><br>
Blurb: <input type="text" name="blurb"/><br>
<input type="submit" value="Add Book"/>
</form>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment