Commit 7fa2cc8c authored by John Riz Daniel Ramos's avatar John Riz Daniel Ramos

Created add-book template

+ add-book.html
+ class: BooksCreateView and BooksUpdateView
+ path "books/add" in urlpattterns in urls.py
parent 2ea96590
......@@ -3,5 +3,6 @@
#ignores midtermenv virtual env
midtermenv/
**/**/*.pyc
.DS_Store
*.pyc
from django.urls import path
from .views import home_view, BooksListView, BooksDetailView, AuthorsView, AuthorsDetailView
from .views import home_view, BooksListView, BooksDetailView, AuthorsView, AuthorsDetailView, BooksCreateView, BooksUpdateView
urlpatterns = [
path('home/', home_view, name='home_view'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/add', BooksCreateView.as_view(), name='books-create'),
path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/', AuthorsView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
......
from django.shortcuts import render
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books
......@@ -20,6 +20,18 @@ class BooksDetailView(DetailView):
template_name = "bookshelf/book_detais.html"
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = "bookshelf/add-book.html"
class BooksUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = "bookshelf/add-book.html"
class AuthorsView(ListView):
model = Author
template_name = "bookshelf/authors.html"
......
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% 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="/books" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
......@@ -5,7 +5,11 @@
{% block content %}
<h1>Welcome to {{ name }}'s Database of Favorite Books and Authors!</h1>
<p>I haven't read a single novel in my life under my own volition. I do not like to read, I have read none of the books that are present in the database. I have watched videos on why I should read them though. So with that in mind, I also don't have a favorite genre or author. If this database were a literary genre it would be classified as fiction.</p>
<br>
<a href="/books">Books</a>
<a href="/authors">Authors</a>
<br>
<a href="/books/add">Add Book</a>
<a href="/authors/add">Add Author</a>
{% 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