Remove get_queryset fallback

master
Jaap Roes 2017-03-16 14:44:51 +01:00
parent f17db22938
commit ac507e4484
2 changed files with 7 additions and 24 deletions

View File

@ -38,13 +38,7 @@ class SortableAdminBase(object):
its sort order can be changed. This view adds a link to the its sort order can be changed. This view adds a link to the
object_tools block to take people to the view to change the sorting. object_tools block to take people to the view to change the sorting.
""" """
if get_is_sortable(self.get_queryset(request)):
try:
qs_method = getattr(self, 'get_queryset', self.queryset)
except AttributeError:
qs_method = self.get_queryset
if get_is_sortable(qs_method(request)):
self.change_list_template = \ self.change_list_template = \
self.sortable_change_list_with_sort_link_template self.sortable_change_list_with_sort_link_template
self.is_sortable = True self.is_sortable = True
@ -137,11 +131,7 @@ class SortableAdmin(SortableAdminBase, ModelAdmin):
pass pass
# Apply any sort filters to create a subset of sortable objects # Apply any sort filters to create a subset of sortable objects
try: objects = self.get_queryset(request).filter(**filters)
qs_method = getattr(self, 'get_queryset', self.queryset)
except AttributeError:
qs_method = self.get_queryset
objects = qs_method(request).filter(**filters)
# Determine if we need to regroup objects relative to a # Determine if we need to regroup objects relative to a
# foreign key specified on the model class that is extending Sortable. # foreign key specified on the model class that is extending Sortable.
@ -315,20 +305,13 @@ class SortableInlineBase(SortableAdminBase, InlineModelAdmin):
' (or Sortable for legacy implementations)') ' (or Sortable for legacy implementations)')
def get_queryset(self, request): def get_queryset(self, request):
if VERSION < (1, 6): qs = super(SortableInlineBase, self).get_queryset(request)
qs = super(SortableInlineBase, self).queryset(request)
else:
qs = super(SortableInlineBase, self).get_queryset(request)
if get_is_sortable(qs): if get_is_sortable(qs):
self.model.is_sortable = True self.model.is_sortable = True
else: else:
self.model.is_sortable = False self.model.is_sortable = False
return qs return qs
if VERSION < (1, 6):
queryset = get_queryset
class SortableTabularInline(TabularInline, SortableInlineBase): class SortableTabularInline(TabularInline, SortableInlineBase):
"""Custom template that enables sorting for tabular inlines""" """Custom template that enables sorting for tabular inlines"""

View File

@ -26,8 +26,8 @@ class ComponentInline(SortableStackedInline):
# ) # )
model = Component model = Component
def queryset(self, request): def get_queryset(self, request):
qs = super(ComponentInline, self).queryset( qs = super(ComponentInline, self).get_queryset(
request).exclude(title__icontains='2') request).exclude(title__icontains='2')
if get_is_sortable(qs): if get_is_sortable(qs):
self.model.is_sortable = True self.model.is_sortable = True
@ -37,14 +37,14 @@ class ComponentInline(SortableStackedInline):
class WidgetAdmin(SortableAdmin): class WidgetAdmin(SortableAdmin):
def queryset(self, request): def get_queryset(self, request):
""" """
A simple example demonstrating that adminsortable works even in A simple example demonstrating that adminsortable works even in
situations where you need to filter the queryset in admin. Here, situations where you need to filter the queryset in admin. Here,
we are just filtering out `widget` instances with an pk higher we are just filtering out `widget` instances with an pk higher
than 3 than 3
""" """
qs = super(WidgetAdmin, self).queryset(request) qs = super(WidgetAdmin, self).get_queryset(request)
return qs.filter(id__lte=3) return qs.filter(id__lte=3)
inlines = [ComponentInline] inlines = [ComponentInline]