You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classDynamicSerializerMetadata(SimpleMetadata): defdetermine_actions(self, request, view): actions= {} formethodin {"PUT", "POST"} &set(view.allowed_methods): view.request=clone_request(request, method) try: # Test global permissionsifhasattr(view, "check_permissions"): view.check_permissions(view.request) # Test object permissionsifmethod=="PUT"andhasattr(view, "get_object"): view.get_object() except (exceptions.APIException, PermissionDenied, Http404): passelse: # If user has appropriate permissions for the view, include# appropriate metadata about the fields that should be supplied.view.action=view.action_map.get(method.lower()) # <----- SET TO CORRECT ACTION BEFORE CALLING get_serializerserializer=view.get_serializer() view.action="metadata"# <------ RESTOREactions[method] =self.get_serializer_info(serializer) finally: view.request=requestreturnactions
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Assume an app that manages information about countries:
OPTIONS
/country/
Expected Behavior
POST
action reflectsCountryCreateSerializer
fields:Actual Behavior
POST
action reflectsCountrySerializer
fields:Explanation / Resolution
SimpleMetadata.determine_actions
should take the action specific serializers into account.Current workaround
Beta Was this translation helpful? Give feedback.
All reactions