Commit afc77108 authored by Nics De Vega's avatar Nics De Vega

Created forms and add pages for books and authors

parent a719b59d
Denise Nicole H. De Vega
211951
2 BSMS CS
CSCI 40 E
Lab 03: My Favorite Books and Authors
March 27, 2023
Lab 04: My Favorite Books and Authors v2
April 25, 2023
This lab activity has been truthfully completed by me.
I can say that with full confidence because my slay is too powerful #yasslay.
<sgd> Denise Nicole H. De Vega, 03/27/2023
\ No newline at end of file
# app/forms.py
from django import forms
from .models import Book, Author
class BookForm(forms.ModelForm):
class Meta:
model = Book
fields = ['Title', 'Author', 'Publisher','Year Published','ISBN','Blurb']
class AuthorForm(forms.ModelForm):
class Meta:
model = Author
fields = ['First Name', 'Last Name', 'Age','Nationality','Bio']
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<br>
<form action="authors/<int:pk>/details/" 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' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<br>
<form action="books/<int:pk>/details/" 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
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<br>
<form action="/" method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Book{% endblock %}
{% block content %}
<br>
<form action="/" method="post">
{% csrf_token %}
{% for field in form %}
{{field.label}}:{{field}} <br><br>
{% endfor %}
<input type="submit" value="Submit">
</form>
{% endblock %}
\ No newline at end of file
......@@ -10,8 +10,8 @@
<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>
<a href="../books/add/">Add Book</a>
<a href="../authors/add/">Add Author</a>
</small>
</h2>
......
from django.urls import path
from .views import homepage, index_view, BooksView, AuthorsView, BooksDetailView, AuthorsDetailView, BooksCreateView, BooksUpdateView, AuthorsCreateView, AuthorsUpdateView
from .views import (
homepage, index_view, BooksView, AuthorsView, BooksDetailView, AuthorsDetailView,
BooksCreateView, BooksUpdateView, AuthorsCreateView, AuthorsUpdateView
)
urlpatterns = [
path('',index_view,name='index'),
path('home/',homepage,name='home'),
......@@ -9,10 +13,12 @@ urlpatterns = [
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='update_book'),
path('authors/',AuthorsView.as_view(),name='authors'),
path('authors/<int:pk>/details/',AuthorsDetailView.as_view(),name='author_details'),
path('authors/add/',AuthorsCreateView.as_view(),name='add_author'),
path('authors/<int:pk>/edit/',BooksUpdateView.as_view(),name='update_author'),
path('authors/<int:pk>/edit/',AuthorsUpdateView.as_view(),name='update_author'),
]
app_name = 'bookshelf'
\ No newline at end of file
......@@ -22,12 +22,12 @@ class BooksDetailView(DetailView):
class BooksCreateView(CreateView):
model = Book
fields = '__all__'
template_name = "bookshelf/add_book.html"
template_name = "bookshelf/add-book.html"
class BooksUpdateView(UpdateView):
model = Book
fields = '__all__'
template_name = "bookshelf/edit_book.html"
template_name = "bookshelf/edit-book.html"
class AuthorsView(ListView):
model = Author
......@@ -40,9 +40,9 @@ class AuthorsDetailView(DetailView):
class AuthorsCreateView(CreateView):
model = Author
fields = '__all__'
template_name = "bookshelf/add_author.html"
template_name = "bookshelf/add-author.html"
class AuthorsUpdateView(UpdateView):
model = Book
fields = '__all__'
template_name = "bookshelf/edit_author.html"
\ No newline at end of file
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