mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 19:14:01 +03:00
Fix guardian import (#4612)
This commit is contained in:
parent
0fe0e1e703
commit
30bf9df5d0
|
@ -207,7 +207,6 @@ guardian = None
|
|||
try:
|
||||
if 'guardian' in settings.INSTALLED_APPS:
|
||||
import guardian
|
||||
import guardian.shortcuts # Fixes #1624
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
|
|
@ -289,6 +289,11 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
|||
perm_format = '%(app_label)s.view_%(model_name)s'
|
||||
|
||||
def filter_queryset(self, request, queryset, view):
|
||||
# We want to defer this import until run-time, rather than import-time.
|
||||
# See https://github.com/tomchristie/django-rest-framework/issues/4608
|
||||
# (Also see #1624 for why we need to make this import explicitly)
|
||||
from guardian.shortcuts import get_objects_for_user
|
||||
|
||||
extra = {}
|
||||
user = request.user
|
||||
model_cls = queryset.model
|
||||
|
@ -302,4 +307,4 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
|
|||
extra = {'accept_global_perms': False}
|
||||
else:
|
||||
extra = {}
|
||||
return guardian.shortcuts.get_objects_for_user(user, permission, queryset, **extra)
|
||||
return get_objects_for_user(user, permission, queryset, **extra)
|
||||
|
|
Loading…
Reference in New Issue
Block a user