Commit 7e5a802f authored by KaoruSawade's avatar KaoruSawade

Implemented adding books: created add-book.html & edited urls.py and views.py

parent 3f3419f3
{% extends 'base.html' %}
{% load static %}
{% block title %}Add New Book{% endblock %}
{% block content %}
<form action='' method="POST">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Add Book">
</form>
{% endblock %}
from django.urls import path from django.urls import path
from .views import home, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView from .views import home, AuthorListView, AuthorDetailView, BooksListView, BooksDetailView, BooksCreateView
urlpatterns = [ urlpatterns = [
path('home/', home, name='home'), path('home/', home, name='home'),
...@@ -7,6 +7,7 @@ urlpatterns = [ ...@@ -7,6 +7,7 @@ urlpatterns = [
path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'), path('authors/<int:pk>/details', AuthorDetailView.as_view(), name='author-detail'),
path('books/', BooksListView.as_view(), name='books-list'), path('books/', BooksListView.as_view(), name='books-list'),
path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'), path('books/<int:pk>/details', BooksDetailView.as_view(), name='books-detail'),
path('books/add', BooksCreateView.as_view(), name='add-book'),
] ]
app_name = "bookshelf" app_name = "bookshelf"
...@@ -2,6 +2,7 @@ from django.shortcuts import render ...@@ -2,6 +2,7 @@ from django.shortcuts import render
from django.views import View from django.views import View
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 django.views.generic.edit import CreateView, UpdateView
from .models import Author, Books from .models import Author, Books
def home(request): def home(request):
...@@ -28,3 +29,8 @@ class BooksDetailView(DetailView): ...@@ -28,3 +29,8 @@ class BooksDetailView(DetailView):
book = Books.objects.get(pk=pk) book = Books.objects.get(pk=pk)
author = book.author author = book.author
return render(request, 'bookshelf/books_detail.html', {'author': author, 'book': book}) return render(request, 'bookshelf/books_detail.html', {'author': author, 'book': book})
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.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