File tree Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Expand file tree Collapse file tree 1 file changed +39
-2
lines changed Original file line number Diff line number Diff line change 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
2
5
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
You can’t perform that action at this time.
0 commit comments