Skip to content

Commit

Permalink
add get_queryset as perferred alternative to _meta.model
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRiina committed Nov 18, 2015
1 parent e7bf8e5 commit dd730c3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions django_object_actions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,15 @@ def decorated_function(self, request, queryset):
# https://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#writing-action-functions
if not isinstance(queryset, QuerySet):
try:
model = queryset._meta.model
# Django >=1.8
queryset = self.get_queryset(request).filter(pk=queryset.pk)
except AttributeError:
# Django 1.5 does this instead, getting the model may be overkill
# we may be able to throw away all this logic
model = queryset._meta.concrete_model

queryset = model.objects.filter(pk=queryset.pk)
try:
# Django >=1.6,<1.8
model = queryset._meta.model
except AttributeError:
# Django <1.6
model = queryset._meta.concrete_model
queryset = model.objects.filter(pk=queryset.pk)
return func(self, request, queryset)
return decorated_function

0 comments on commit dd730c3

Please sign in to comment.