15
15
class ChoiceAdmin (DjangoObjectActions , admin .ModelAdmin ):
16
16
list_display = ('poll' , 'choice_text' , 'votes' )
17
17
18
+ # Actions
19
+ #########
20
+
18
21
@takes_instance_or_queryset
19
22
def increment_vote (self , request , queryset ):
20
23
queryset .update (votes = F ('votes' ) + 1 )
@@ -26,6 +29,11 @@ def increment_vote(self, request, queryset):
26
29
'class' : 'addlink' ,
27
30
}
28
31
32
+ actions = ['increment_vote' ]
33
+
34
+ # Object actions
35
+ ################
36
+
29
37
def decrement_vote (self , request , obj ):
30
38
obj .votes -= 1
31
39
obj .save ()
@@ -51,8 +59,6 @@ def raise_key_error(self, request, obj):
51
59
'raise_key_error' ,
52
60
)
53
61
changelist_actions = ('delete_all' ,)
54
- actions = ['increment_vote' ]
55
-
56
62
admin .site .register (Choice , ChoiceAdmin )
57
63
58
64
@@ -62,16 +68,34 @@ class ChoiceInline(admin.StackedInline):
62
68
63
69
64
70
class PollAdmin (DjangoObjectActions , admin .ModelAdmin ):
71
+ # List
72
+ ######
73
+
74
+ list_display = ('question' , 'pub_date' , 'was_published_recently' )
75
+ list_filter = ['pub_date' ]
76
+ search_fields = ['question' ]
77
+ date_hierarchy = 'pub_date'
78
+
79
+ def changelist_view (self , request , extra_context = None ):
80
+ extra_context = {'foo' : 'changelist_view' }
81
+ return super (PollAdmin , self ).changelist_view (request , extra_context )
82
+
83
+ # Detail
84
+ ########
85
+
65
86
fieldsets = [
66
87
(None , {'fields' : ['question' ]}),
67
88
('Date information' ,
68
89
{'fields' : ['pub_date' ], 'classes' : ['collapse' ]}),
69
90
]
70
91
inlines = [ChoiceInline ]
71
- list_display = ('question' , 'pub_date' , 'was_published_recently' )
72
- list_filter = ['pub_date' ]
73
- search_fields = ['question' ]
74
- date_hierarchy = 'pub_date'
92
+
93
+ def change_view (self , request , object_id , form_url = '' , extra_context = None ):
94
+ extra = {'foo' : 'change_view' }
95
+ return super (PollAdmin , self ).change_view (request , object_id , form_url , extra )
96
+
97
+ # Object actions
98
+ ################
75
99
76
100
def delete_all_choices (self , request , obj ):
77
101
from django .shortcuts import render_to_response
@@ -105,11 +129,14 @@ def get_change_actions(self, request, object_id, form_url):
105
129
actions .remove ('question_mark' )
106
130
107
131
return actions
108
-
109
132
admin .site .register (Poll , PollAdmin )
110
133
111
134
112
135
class CommentAdmin (DjangoObjectActions , admin .ModelAdmin ):
136
+
137
+ # Object actions
138
+ ################
139
+
113
140
def hodor (self , request , obj ):
114
141
if not obj .comment :
115
142
# bail because we need a comment
0 commit comments