1
+ from __future__ import unicode_literals
2
+
1
3
from django .contrib import admin
2
4
from django .core .urlresolvers import reverse
3
5
from django .db .models import F
6
8
from django_object_actions import (DjangoObjectActions ,
7
9
takes_instance_or_queryset )
8
10
9
- from .models import Choice , Poll
11
+ from .models import Choice , Poll , Comment
10
12
11
13
12
14
class ChoiceAdmin (DjangoObjectActions , admin .ModelAdmin ):
@@ -51,7 +53,7 @@ class ChoiceInline(admin.StackedInline):
51
53
52
54
class PollAdmin (DjangoObjectActions , admin .ModelAdmin ):
53
55
fieldsets = [
54
- (None , {'fields' : ['question' ]}),
56
+ (None , {'fields' : ['question' ]}),
55
57
('Date information' , {'fields' : ['pub_date' ], 'classes' : ['collapse' ]}),
56
58
]
57
59
inlines = [ChoiceInline ]
@@ -74,6 +76,15 @@ def delete_all_choices(self, request, obj):
74
76
delete_all_choices .label = "Delete All Choices"
75
77
76
78
objectactions = ('delete_all_choices' , )
79
+ admin .site .register (Poll , PollAdmin )
77
80
78
81
79
- admin .site .register (Poll , PollAdmin )
82
+ class CommentAdmin (DjangoObjectActions , admin .ModelAdmin ):
83
+ def hodor (self , request , obj ):
84
+ if not obj .comment :
85
+ # bail because we need a comment
86
+ return
87
+ obj .comment = ' ' .join (['hodor' for x in obj .comment .split ()])
88
+ obj .save ()
89
+ objectactions = ('hodor' , )
90
+ admin .site .register (Comment , CommentAdmin )
0 commit comments