mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-08 06:14:47 +03:00
Merge 3c160fa153
into 9b56dda918
This commit is contained in:
commit
d0a03ac736
|
@ -136,7 +136,21 @@ class SimpleMetadata(BaseMetadata):
|
|||
field_info['child'] = self.get_field_info(field.child)
|
||||
elif getattr(field, 'fields', None):
|
||||
field_info['children'] = self.get_serializer_info(field)
|
||||
|
||||
|
||||
if isinstance(field, serializers.PrimaryKeyRelatedField):
|
||||
try:
|
||||
perm_format = '%(app_label)s.view_%(model_name)s'
|
||||
model_cls = field.queryset.model
|
||||
kwargs = {
|
||||
'app_label': model_cls._meta.app_label,
|
||||
'model_name': get_model_name(model_cls)
|
||||
}
|
||||
permission = perm_format % kwargs
|
||||
|
||||
field.queryset= guardian.shortcuts.get_objects_for_user(request.user, permission, field.queryset, accept_global_perms= False)
|
||||
except:
|
||||
field.queryset=[]
|
||||
|
||||
if not field_info.get('read_only') and hasattr(field, 'choices'):
|
||||
field_info['choices'] = [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user