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 @@
{{ object.age }}<br>
{{ object.nationality }}<br>
{{ object.bio }}<br><br>
<a href='/bookshelf/authors/{{ object.pk }}/edit/'>Edit Author</a><br><br>
Books by {{ object }} I love:
<ul>
{% for book in object.writings.all %}
......@@ -15,7 +16,7 @@
{% endfor %}
</ul><br><br>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/authors/'>Authors</a>
......
......@@ -8,8 +8,9 @@
{{ object.year_published }}<br>
{{ object.ISBN }}<br>
{{ object.blurb }}<br><br>
<a href='/bookshelf/books/{{ object.pk }}/edit/'>Edit Book</a><br><br>
<a href='/bookshelf/home/'>Home</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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 @@
<p>
{{ description }}<br><br>
<a href='/bookshelf/books/'>Books</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
<a href='/bookshelf/authors/'>Authors</a>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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>
{% endblock %}
\ No newline at end of file
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 = [
path('home/', home_view, name='home_view'),
path('authors/', AuthorListView.as_view(), name='authors'),
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/<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'
\ No newline at end of file
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from django.views.generic.list import ListView
from .models import Author, Books
......@@ -17,10 +18,30 @@ class AuthorDetailView(DetailView):
model = Author
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):
model = Books
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView):
model = Books
template_name = 'bookshelf/book_details.html'
\ No newline at end of file
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