Skip to content

Commit d4a3c2a

Browse files
author
Ryan P Kilby
committed
Move import_class to utils
1 parent 3634045 commit d4a3c2a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

rest_framework_filters/filters.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44
from django.utils import six
55

66
from django_filters.rest_framework.filters import *
7+
from rest_framework_filters.utils import import_class
78

89

910
ALL_LOOKUPS = '__all__'
1011

1112

12-
def _import_class(path):
13-
module_path, class_name = path.rsplit('.', 1)
14-
class_name = str(class_name) # Ensure not unicode on py2.x
15-
module = __import__(module_path, fromlist=[class_name], level=0)
16-
return getattr(module, class_name)
17-
18-
1913
class AutoFilter(Filter):
2014
def __init__(self, *args, **kwargs):
2115
self.lookups = kwargs.pop('lookups', [])
@@ -33,7 +27,7 @@ def __init__(self, filterset, *args, **kwargs):
3327
def filterset():
3428
def fget(self):
3529
if isinstance(self._filterset, six.string_types):
36-
self._filterset = _import_class(self._filterset)
30+
self._filterset = import_class(self._filterset)
3731
return self._filterset
3832

3933
def fset(self, value):

rest_framework_filters/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
from django.utils import six
1010

1111

12+
def import_class(path):
13+
module_path, class_name = path.rsplit('.', 1)
14+
class_name = str(class_name) # Ensure not unicode on py2.x
15+
module = __import__(module_path, fromlist=[class_name], level=0)
16+
return getattr(module, class_name)
17+
18+
1219
def lookups_for_field(model_field):
1320
"""
1421
Generates a list of all possible lookup expressions for a model field.

0 commit comments

Comments
 (0)