Commit b80b35b6 authored by Migs Atienza's avatar Migs Atienza

Added add book page

parent 4f90495d
settings.py
\ No newline at end of file
...@@ -2,7 +2,7 @@ Miguel Luis Antonio A. Atienza ...@@ -2,7 +2,7 @@ Miguel Luis Antonio A. Atienza
210523 210523
BS CS - DGDD BS CS - DGDD
F F
Lab 03: My Favorite Books and Authors Lab 04: My Favorite Books and Authors v2
April 13, 2023 April 30, 2023
This lab requirement was made by me and only me. This lab requirement was made by me and only me.
<sgd> Miguel Luis Antonio A. Atienza, April 13, 2023 <sgd> Miguel Luis Antonio A. Atienza, April 30, 2023
{% extends 'base.html' %}
{% block title %}Add New Book{% endblock %}
{% block content %}<center>
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" value="Add Book" />
</form>
</center>{% endblock %}
{% block links %}
<center><br/><br/><br/><br/><br/>
<a href="/bookshelf/home">Home</a>
<a href="/bookshelf/books">Books</a>
<a href="/bookshelf/authors">Authors</a></center>
{% endblock %}
\ No newline at end of file
...@@ -8,5 +8,7 @@ a while back. An author I enjoy here would be Rick Riordan and his Percy Jackson ...@@ -8,5 +8,7 @@ a while back. An author I enjoy here would be Rick Riordan and his Percy Jackson
{% block links %} {% block links %}
<center><br/><br/><br/><br/><br/> <center><br/><br/><br/><br/><br/>
<a href="books">Books</a> <a href="books">Books</a>
<a>Add Book</a>
<a href="authors">Authors</a></center> <a href="authors">Authors</a></center>
<a>Add Author</a>
{% endblock %} {% endblock %}
from django.urls import path from django.urls import path
from .views import index, home_view, BooksListView, BooksDetailView, AuthorsListView, AuthorsDetailView from .views import index, home_view, BooksListView, BooksDetailView, BooksCreateView, AuthorsListView, \
AuthorsDetailView
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', index, name='index'),
path('home', home_view, name='home_view'), path('home', home_view, name='home_view'),
path('books', BooksListView.as_view(), name='books_list'), path('books', BooksListView.as_view(), name='books_list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books_details'), path('books/<int:pk>/details', BooksDetailView.as_view(), name='books_details'),
path('books/add', BooksCreateView.as_view(), name='add_book'),
path('authors', AuthorsListView.as_view(), name='authors_list'), path('authors', AuthorsListView.as_view(), name='authors_list'),
path('authors/<int:pk>/details', AuthorsDetailView.as_view(), name='authors_details'), path('authors/<int:pk>/details', AuthorsDetailView.as_view(), name='authors_details'),
] ]
......
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.list import ListView from django.views.generic.list import ListView
from django.views.generic.edit import CreateView, UpdateView
from django.http import HttpResponse from django.http import HttpResponse
from .models import Author, Book from .models import Author, Book
...@@ -24,6 +25,12 @@ class BooksDetailView(DetailView): ...@@ -24,6 +25,12 @@ class BooksDetailView(DetailView):
template_name = "bookshelf/books_details.html" template_name = "bookshelf/books_details.html"
class BooksCreateView(CreateView):
model = Book
fields = '__all__'
template_name = "bookshelf/add-book.html"
class AuthorsListView(ListView): class AuthorsListView(ListView):
model = Author model = Author
template_name = "bookshelf/authors.html" template_name = "bookshelf/authors.html"
...@@ -32,4 +39,7 @@ class AuthorsListView(ListView): ...@@ -32,4 +39,7 @@ class AuthorsListView(ListView):
class AuthorsDetailView(DetailView): class AuthorsDetailView(DetailView):
model = Author model = Author
template_name = "bookshelf/authors_details.html" template_name = "bookshelf/authors_details.html"
# Create your views here. # Create your views here.
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