Commit 67815043 authored by KaoruSawade's avatar KaoruSawade

Implemented adding authors: created add-author.html & edited urls.py and views.py

parent 7e5a802f
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Author{% endblock %}
{% block content %}
<form action='' method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Author">
</form>
{% endblock %}
from django.urls import path
from .views import home, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, BooksCreateView
from .views import home, AuthorListView, AuthorDetailView, AuthorCreateView, BooksListView, BooksDetailView, BooksCreateView
urlpatterns = [
path('home/', home, name='home'),
path('authors/', AuthorListView.as_view(), name='author-list'),
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
path('authors/add', AuthorCreateView.as_view(), name='add-book'),
path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('books/add', BooksCreateView.as_view(), name='add-book'),
......
......@@ -19,6 +19,11 @@ class AuthorDetailView(DetailView):
book_list = Books.objects.filter(author__first_name__exact=author.first_name)
return render(request, 'bookshelf/author_detail.html', {'author': author, 'book_list': book_list})
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class BooksListView(ListView):
def get(self, request):
books_list = Books.objects.all()
......
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