Commit 10c0a92c authored by Jenica Vizmanos's avatar Jenica Vizmanos

Created forms.py and html files and modified views.py, urls.py, and other existing html files

parent 8114b9e2
from django import forms
from .models import Author, Books
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = '__all__'
class BooksForm(forms.ModelForm):
class Meta:
model = Books
fields = '__all__'
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<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 %}
<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
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
{{ object.age }}<br> {{ object.age }}<br>
{{ object.nationality }}<br> {{ object.nationality }}<br>
{{ object.bio }}<br><br> {{ object.bio }}<br><br>
<a href='/bookshelf/authors/{{ object.pk }}/edit/'>Edit Author</a><br><br>
Books by {{ object }} I love: Books by {{ object }} I love:
<ul> <ul>
{% for book in object.writings.all %} {% for book in object.writings.all %}
...@@ -15,7 +16,7 @@ ...@@ -15,7 +16,7 @@
{% endfor %} {% endfor %}
</ul><br><br> </ul><br><br>
<a href='/bookshelf/home/'>Home</a> <a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/books/'>Books</a> <a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a> <a href='/bookshelf/authors/'>Authors</a>
......
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
{{ object.year_published }}<br> {{ object.year_published }}<br>
{{ object.ISBN }}<br> {{ object.ISBN }}<br>
{{ object.blurb }}<br><br> {{ object.blurb }}<br><br>
<a href='/bookshelf/books/{{ object.pk }}/edit/'>Edit Book</a><br><br>
<a href='/bookshelf/home/'>Home</a> <a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/books/'>Books</a> <a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a> <a href='/bookshelf/authors/'>Authors</a>
......
{% extends 'base.html' %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<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 %}
<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
...@@ -5,7 +5,10 @@ ...@@ -5,7 +5,10 @@
<p> <p>
{{ description }}<br><br> {{ description }}<br><br>
<a href='/bookshelf/books/'>Books</a> <a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a> <a href='/bookshelf/authors/'>Authors</a><br>
<a href='/bookshelf/books/add/'>Add Book</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/add/'>Add Author</a>
</p> </p>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import home_view, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView from .views import (
home_view, AuthorListView, AuthorDetailView, AuthorCreateView, AuthorUpdateView,
BooksListView, BooksDetailView, BooksCreateView, BooksUpdateView
)
urlpatterns = [ urlpatterns = [
path('home/', home_view, name='home_view'), path('home/', home_view, name='home_view'),
path('authors/', AuthorListView.as_view(), name='authors'), path('authors/', AuthorListView.as_view(), name='authors'),
path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author_details'), path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='author_details'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
path('authors/<int:pk>/edit/', AuthorUpdateView.as_view(), name='edit-author'),
path('books/', BooksListView.as_view(), name='books'), path('books/', BooksListView.as_view(), name='books'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='book_details'),
path('books/add/', BooksCreateView.as_view(), name='add-book'),
path('books/<int:pk>/edit/', BooksUpdateView.as_view(), name='edit-book'),
] ]
app_name = 'bookshelf' app_name = 'bookshelf'
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.list import ListView from django.views.generic.list import ListView
from .models import Author, Books from .models import Author, Books
...@@ -17,6 +18,16 @@ class AuthorDetailView(DetailView): ...@@ -17,6 +18,16 @@ class AuthorDetailView(DetailView):
model = Author model = Author
template_name = 'bookshelf/author_details.html' template_name = 'bookshelf/author_details.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'
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html' template_name = 'bookshelf/books.html'
...@@ -24,3 +35,13 @@ class BooksListView(ListView): ...@@ -24,3 +35,13 @@ class BooksListView(ListView):
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/book_details.html' template_name = 'bookshelf/book_details.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.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