Commit fb4cf22b authored by Joei Yucoco's avatar Joei Yucoco

Added working books/add/ url

parent 733e2684
<!DOCTYPE html>
{% extends 'base.html' %}
{% block title %}My Favorite Authors{% endblock %}
{% block content %}
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
from django.urls import path
from .views import HomeView, BooksView, BookDetailsView, AuthorsView, AuthorDetailsView, AuthorAddView
from .views import (HomeView, BooksView, BookDetailsView,
AuthorsView, AuthorDetailsView, AuthorAddView, BookAddView)
urlpatterns = [
path('home/', HomeView, name='home'),
......@@ -8,6 +9,7 @@ urlpatterns = [
path('authors/', AuthorsView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorDetailsView.as_view(), name='authors-detail'),
path('authors/add/', AuthorAddView, name='authors-add'),
path('books/add/', BookAddView, name='books-add'),
]
app_name = "bookshelf"
......@@ -34,15 +34,24 @@ class AuthorDetailsView(DetailView):
#TODO: add template, app urls,
def AuthorAddView(request):
#context ={}
if request.method == 'POST':
form = AuthorForm(request.POST)
if form.is_valid():
new_author = form.save()
#context['form']= form
return redirect('bookshelf:authors-detail', pk=new_author.pk)
else:
form = AuthorForm()
return render(request, 'bookshelf/author_add.html', {'form': form})
def BookAddView(request):
if request.method == 'POST':
form = BooksForm(request.POST)
if form.is_valid():
new_book = form.save()
return redirect('bookshelf:books-detail', pk=new_book.pk)
else:
form = BooksForm()
return render(request, 'bookshelf/book_add.html', {'form': form})
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