Skip to content

Commit

Permalink
use the decorator in the example project
Browse files Browse the repository at this point in the history
also fix typos in the short descriptions
  • Loading branch information
crccheck committed Nov 7, 2013
1 parent e6b5efb commit 35df010
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions example_project/polls/admin.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
from django.contrib import admin
from django.core.urlresolvers import reverse
from django.db.models import F
from django.http import HttpResponseRedirect

from django_object_actions import DjangoObjectActions
from django_object_actions.utils import takes_instance_or_queryset

from .models import Choice, Poll


class ChoiceAdmin(DjangoObjectActions, admin.ModelAdmin):
list_display = ('poll', 'choice_text', 'votes')

def increment_vote(self, request, obj):
obj.votes += 1
obj.save()
@takes_instance_or_queryset
def increment_vote(self, request, queryset):
queryset.update(votes=F('votes') + 1)
increment_vote.short_description = "+1"
increment_vote.label = "vote++"

def decrement_vote(self, request, obj):
obj.votes -= 1
obj.save()
increment_vote.short_description = "-1"
decrement_vote.short_description = "-1"

def reset_vote(self, request, obj):
obj.votes = 0
obj.save()
increment_vote.short_description = "0"
reset_vote.short_description = "0"

def edit_poll(self, request, obj):
url = reverse('admin:polls_poll_change', args=(obj.poll.pk,))
return HttpResponseRedirect(url)

objectactions = ('increment_vote', 'decrement_vote', 'reset_vote',
'edit_poll')
actions = ['increment_vote']

admin.site.register(Choice, ChoiceAdmin)

Expand Down

0 comments on commit 35df010

Please sign in to comment.