Updated vies.py to add create and update view

parent bdb86e50
from django.shortcuts import render from django.shortcuts import render
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.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Books, Author from .models import Books, Author
...@@ -9,17 +10,48 @@ def home_view(request): ...@@ -9,17 +10,48 @@ def home_view(request):
return render(request, 'bookshelf/home.html', {'nickname': 'Dani'}) return render(request, 'bookshelf/home.html', {'nickname': 'Dani'})
class BooksView(ListView): class AuthorsListView(ListView):
model = Author
template_name = 'bookshelf/authors.html'
class AuthorsDetailView(DetailView):
model = Author
template_name = 'bookshelf/author_details.html'
class BooksListView(ListView):
model = Books model = Books
template_name = 'bookshelf/books.html'
class BooksDetailView(DetailView): class BooksDetailView(DetailView):
model = Books model = Books
template_name = 'bookshelf/books_details.html'
class AuthorView(ListView): class AuthorCreateView(CreateView):
model = Author model = Author
fields = '__all__'
template_name = 'bookshelf/add-author.html'
class AuthorDetailView(DetailView): class BookCreateView(CreateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/add-book.html'
class AuthorUpdateView(UpdateView):
model = Author model = Author
fields = '__all__'
template_name = 'bookshelf/edit-author.html'
class BookUpdateView(UpdateView):
model = Books
fields = '__all__'
template_name = 'bookshelf/edit-book.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