16
16
from django .utils .encoding import force_text
17
17
from django .utils .translation import ugettext_lazy as _
18
18
19
- from rest_framework .compat import coreapi , coreschema , distinct , guardian
19
+ from rest_framework .compat import (
20
+ coreapi , coreschema , distinct , is_guardian_installed
21
+ )
20
22
from rest_framework .settings import api_settings
21
23
22
24
@@ -282,14 +284,15 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
282
284
has read object level permissions.
283
285
"""
284
286
def __init__ (self ):
285
- assert guardian , 'Using DjangoObjectPermissionsFilter, but django-guardian is not installed'
287
+ assert is_guardian_installed () , 'Using DjangoObjectPermissionsFilter, but django-guardian is not installed'
286
288
287
289
perm_format = '%(app_label)s.view_%(model_name)s'
288
290
289
291
def filter_queryset (self , request , queryset , view ):
290
292
# We want to defer this import until run-time, rather than import-time.
291
293
# See https://github.com/encode/django-rest-framework/issues/4608
292
294
# (Also see #1624 for why we need to make this import explicitly)
295
+ from guardian import VERSION as guardian_version
293
296
from guardian .shortcuts import get_objects_for_user
294
297
295
298
extra = {}
@@ -300,7 +303,7 @@ def filter_queryset(self, request, queryset, view):
300
303
'model_name' : model_cls ._meta .model_name
301
304
}
302
305
permission = self .perm_format % kwargs
303
- if tuple (guardian . VERSION ) >= (1 , 3 ):
306
+ if tuple (guardian_version ) >= (1 , 3 ):
304
307
# Maintain behavior compatibility with versions prior to 1.3
305
308
extra = {'accept_global_perms' : False }
306
309
else :
0 commit comments