Skip to content

Commit 40d8e5f

Browse files
committed
Add views with genericview
1 parent b363fae commit 40d8e5f

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

books/views.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1-
from django.shortcuts import render
1+
from django.views.generic.base import TemplateView
2+
from django.views.generic import ListView
3+
from django.views.generic import DetailView
4+
from books.models import Book, Author, Publisher
25

3-
# Create your views here.
6+
7+
#-- TemplateView
8+
class BooksModelView(TemplateView):
9+
template_name = 'books/index.html'
10+
11+
def get_context_data(self, **kwargs):
12+
context = super(BooksModelView, self).get_context_data(**kwargs)
13+
context['object_list'] = ['Book', 'Author', 'Publisher']
14+
return context
15+
16+
17+
#-- ListView
18+
class BookList(ListView):
19+
model = Book
20+
21+
22+
class AuthorList(ListView):
23+
model = Author
24+
25+
26+
class PublisherList(ListView):
27+
model = Publisher
28+
29+
30+
#-- DetailView
31+
class BookDetail(DetailView):
32+
model = Book
33+
34+
35+
class AuthorDetail(DetailView):
36+
model = Author
37+
38+
39+
class PublisherDetail(DetailView):
40+
model = Publisher

0 commit comments

Comments
 (0)