mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-07 22:04:48 +03:00
pass instance to view.get_serializer in metadata's determine_actions method since choices (especially querysets of related fields) can often depend on the instance
This commit is contained in:
parent
450c541462
commit
c5d6ecc84c
|
@ -74,19 +74,23 @@ class SimpleMetadata(BaseMetadata):
|
|||
actions = {}
|
||||
for method in set(['PUT', 'POST']) & set(view.allowed_methods):
|
||||
view.request = clone_request(request, method)
|
||||
instance = None
|
||||
try:
|
||||
# Test global permissions
|
||||
if hasattr(view, 'check_permissions'):
|
||||
view.check_permissions(view.request)
|
||||
# Test object permissions
|
||||
if method == 'PUT' and hasattr(view, 'get_object'):
|
||||
view.get_object()
|
||||
instance = view.get_object()
|
||||
except (exceptions.APIException, PermissionDenied, Http404):
|
||||
pass
|
||||
else:
|
||||
# If user has appropriate permissions for the view, include
|
||||
# appropriate metadata about the fields that should be supplied.
|
||||
serializer = view.get_serializer()
|
||||
kwargs = {}
|
||||
if instance is not None:
|
||||
kwargs['instance'] = instance
|
||||
serializer = view.get_serializer(**kwargs)
|
||||
actions[method] = self.get_serializer_info(serializer)
|
||||
finally:
|
||||
view.request = request
|
||||
|
|
Loading…
Reference in New Issue
Block a user