Created Forms for User Input

parent af75f49c
from django import forms
from .models import Author, Books
class BookForm(forms.ModelForm):
class Meta:
model = Books
fields = '__all__'
class SubjectForm(forms.ModelForm):
class Meta:
model = Author
fields = '__all__'
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<br>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Add Author">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<br>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Add Book">
</form>
{% endblock %}
\ No newline at end of file
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<button class="button"><a href="/bookshelf/authors/{{ object.pk }}/edit">Edit Author</a></button>
<center> <center>
<button class="button"><a href="/bookshelf/home">Home</a></button> <button class="button"><a href="/bookshelf/home">Home</a></button>
<button class="button"><a href="/bookshelf/books">Books</a></button> <button class="button"><a href="/bookshelf/books">Books</a></button>
......
...@@ -3,13 +3,14 @@ ...@@ -3,13 +3,14 @@
{% block title %}{{ object.title }}{% endblock %} {% block title %}{{ object.title }}{% endblock %}
{% block content %} {% block content %}
<h1>{{ object.title }}</h1> <h1>{{ object.title }}</h1>
<h3><a href="{{ object.author.get_absolute_url}}"> <h3><a href="{{ object.author.get_absolute_url }}">
{{ object.author }} {{ object.author }}
</a></h3> </a></h3>
<h3>{{ object.publisher }}</h3> <h3>{{ object.publisher }}</h3>
<h3>{{ object.year_published }}</h3> <h3>{{ object.year_published }}</h3>
<h3>{{ object.ISBN }}</h3> <h3>{{ object.ISBN }}</h3>
<p>{{ object.blurb }}</p> <p>{{ object.blurb }}</p>
<button class="button"><a href="/bookshelf/books/{{ object.pk }}/edit">Edit Book</a></button>
<center> <center>
<button class="button"><a href="/bookshelf/home">Home</a></button> <button class="button"><a href="/bookshelf/home">Home</a></button>
<button class="button"><a href="/bookshelf/books">Books</a></button> <button class="button"><a href="/bookshelf/books">Books</a></button>
......
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<br>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<br>
<form method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Save Changes">
</form>
{% endblock %}
\ No newline at end of file
...@@ -11,5 +11,8 @@ ...@@ -11,5 +11,8 @@
<br> <br>
<button class="button"><a href="/bookshelf/books">Books</a></button> <button class="button"><a href="/bookshelf/books">Books</a></button>
<button class="button"><a href="/bookshelf/authors">Authors</a></button> <button class="button"><a href="/bookshelf/authors">Authors</a></button>
<br>
<button class="button"><a href="/bookshelf/books/add/">Add Book</a></button>
<button class="button"><a href="/bookshelf/authors/add/">Add Author</a></button>
</center> </center>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -5,7 +5,11 @@ from .views import ( ...@@ -5,7 +5,11 @@ from .views import (
BooksListView, BooksListView,
BooksDetailView, BooksDetailView,
AuthorsListView, AuthorsListView,
AuthorsDetailView AuthorsDetailView,
BookCreateView,
BookUpdateView,
AuthorCreateView,
AuthorUpdateView
) )
urlpatterns = [ urlpatterns = [
path('home/', index, name='homepage'), path('home/', index, name='homepage'),
...@@ -13,6 +17,10 @@ urlpatterns = [ ...@@ -13,6 +17,10 @@ urlpatterns = [
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
path('authors/', AuthorsListView.as_view(), name='authors'), path('authors/', AuthorsListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='author_details'), path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='author_details'),
path('books/add/', BookCreateView.as_view(), name='book_add'),
path('books/<int:pk>/edit/', BookUpdateView.as_view(), name='book_update'),
path('authors/add/', AuthorCreateView.as_view(), name='author_add'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='author_update'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
\ No newline at end of file
...@@ -3,6 +3,7 @@ from django.http import HttpResponse ...@@ -3,6 +3,7 @@ from django.http import HttpResponse
from django.views import View from django.views import View
from django.views.generic.list import ListView from django.views.generic.list import ListView
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
...@@ -24,3 +25,23 @@ class AuthorsListView(ListView): ...@@ -24,3 +25,23 @@ class AuthorsListView(ListView):
class AuthorsDetailView(DetailView): class AuthorsDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.html'
class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorUpdateView(UpdateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.html'
\ 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