Skip to content

Commit 84bce2c

Browse files
committed
Replace getattr by test against DJANGO_VERSION
1 parent 32e358d commit 84bce2c

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

webstack_django_sorting/templatetags/sorting_tags.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from operator import attrgetter
22

3-
from django import template
3+
from django import template, VERSION as DJANGO_VERSION
44
from django.conf import settings
55
from django.http import Http404
66
from django.utils.translation import ugettext_lazy as _
@@ -134,11 +134,10 @@ def need_python_sorting(self, queryset, ordering):
134134
# Python sorting if not a field
135135
field = ordering[1:] if ordering[0] == '-' else ordering
136136

137-
if getattr(queryset.model._meta, 'get_fields', False):
138-
# Django 1.8+
139-
field_names = [f.name for f in queryset.model._meta.get_fields()]
140-
else:
137+
if DJANGO_VERSION < (1, 8):
141138
field_names = queryset.model._meta.get_all_field_names()
139+
else:
140+
field_names = [f.name for f in queryset.model._meta.get_fields()]
142141

143142
return field not in field_names
144143

0 commit comments

Comments
 (0)