Added add-author view

parent 063e6c85
from django.urls import path
from .views import (
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView, HomepageView
BooksListView, BooksDetailView, AuthorsDetailView, AuthorsListView, HomepageView, AuthorCreateView
)
urlpatterns = [
......@@ -10,4 +10,5 @@ urlpatterns = [
path('authors/', AuthorsListView.as_view(), name='authors-list'),
path('authors/<int:pk>/details/', AuthorsDetailView.as_view(), name='authors-detail'),
path('home/', HomepageView, name='home'),
path('authors/add/', AuthorCreateView.as_view(), name='add-author'),
]
......@@ -3,8 +3,10 @@ from django.shortcuts import render
from django.template import loader
from django.views.generic.list import ListView
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import Author, Books
from .forms import BooksForm, AuthorForm
def HomepageView(request):
......@@ -29,6 +31,17 @@ class AuthorsDetailView(DetailView):
model = Author
class AuthorCreateView(CreateView):
model = Author
fields = '__all__'
template_name = 'add-author.html'
class BooksCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'add-books.html'
'''
books = Books.objects.filter(author=Author)
extra_context = {'books': books.author.all()}
......
<form method="post">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save">
</form>
\ 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