Commit 824e5edd authored by Jose Gabriel L. Salas's avatar Jose Gabriel L. Salas

added books and authors add pages with submit option

parent 0d6e90be
from django import forms
from .models import Books, Author
class AddBookForm(forms.Form):
title = forms.CharField(label='title', max_length=100)
author = forms.CharField(label='author', max_length=100)
publisher = forms.CharField(label='publisher', max_length=100)
year_published = forms.IntegerField(label='year_published')
ISBN = forms.IntegerField(label='ISBN')
blurb = forms.CharField(label='blurb', max_length=500)
class BookForm(forms.ModelForm):
class Meta:
model = Books
fields = ['title', 'author', 'publisher',
'year_published', 'ISBN', 'blurb'
]
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form action = """ method = "post">
{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value ="Add Author"></p>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action="/" method="post">
{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value="Add Book"></p>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% load static %}
{% block title %}Edit Author{% endblock %}
{% block content %}
<form action = "" method = "post">
{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value ="Save Changes"></p>
</form>
{% endblock %}
\ No newline at end of file
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
{% block content %} {% block content %}
<h1>Welcome to Gab's Database of Favorite Books and Authors!</h1> <h1>Welcome to Gab's Database of Favorite Books and Authors!</h1>
<p>I typically enjoy reading books with thought provoking topics, horrific themes, and myseterious plots. Authors that specializes in these appeal to me the most.</p> <p>I typically enjoy reading books with thought provoking topics, horrific themes, and myseterious plots. Authors that specializes in these appeal to me the most.</p>
<a href="/bookshelf/books/">Books</a> <a href="/bookshelf/books/"><center>Books</a>&emsp13;
<a href="/bookshelf/authors/">Authors</a> <a href="/bookshelf/authors/">Authors</center></a><br>
<a href="/bookshelf/books/add"><center>Add Book</a>&emsp13;
<a href="/bookshelf/authors/add">Add Author</center></a>
{% endblock %} {% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index, BooksListView, AuthorListView, BooksDetailView, AuthorDetailView from .views import index, BooksListView, AuthorListView, BooksDetailView, AuthorDetailView, AuthorCreateView, AuthorUpdateView, BookCreateView, BookUpdateView
urlpatterns = [ urlpatterns = [
path('home/', index, name='index'), path('home/', index, name='index'),
path('books/', BooksListView.as_view(), name='books-list'), path('books/', BooksListView.as_view(), name='books-list'),
path('authors/', AuthorListView.as_view(), name='author-list'), path('authors/', AuthorListView.as_view(), name='author-list'),
path('books/<int:pk>', BooksDetailView.as_view(), name='books-detail'), path('books/<int:pk>/details/', BooksDetailView.as_view(), name='books-detail'),
path('authors/<int:pk>', AuthorDetailView.as_view(), name='authors-detail'), path('authors/<int:pk>/details/', AuthorDetailView.as_view(), name='authors-detail'),
# path('books/add/', AddBookView.as_view(), name = 'add-book'),
path('authors/add/', AuthorCreateView.as_view(), name = 'add-author'),
path('authors/<int:pk>/edit', AuthorUpdateView.as_view(), name = 'edit-author'),
path('books/add/', BookCreateView.as_view(), name = 'add-book'),
path('books/<int:pk>/edit', BookUpdateView.as_view(), name = 'edit-book'),
] ]
......
#from django.shortcuts import render #from django.shortcuts import render
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views import View from django.views import View
from .models import Books, Author from .models import Books, Author
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 .forms import AddBookForm, BookForm
from django.views.generic.edit import CreateView, UpdateView
def index(request): def index(request):
return render(request, 'bookshelf/home.html', {'name': 'Gab'}) return render(request, 'bookshelf/home.html', {'name': 'Gab'})
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 BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.html'
class BooksListView(ListView): class BooksListView(ListView):
model = Books model = Books
template_name = "bookshelf/books.html" template_name = "bookshelf/books.html"
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = "bookshelf/book_details.html" template_name = "bookshelf/book_details.html"
......
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