Add a style to hide fields from raw data input from BrowsableAPIRenderer #9900
Unanswered
mdrkrg
asked this question in
Ideas & Suggestions
Replies: 1 comment
-
|
Workaround if this is not implemented in DRF: class HideFieldsMixin:
def get_hide_raw_data_fields(self):
return [
name
for name, field in self.fields.items()
if field.style.get("hide_raw_data")
]
@property
def data(self):
ret = super().data
request = self.context.get("request")
if request and isinstance(request.accepted_renderer, BrowsableAPIRenderer):
for field_name in self.get_hide_raw_data_fields():
ret.pop(field_name, None)
return ret
class TestSerializer(HideFieldsMixin, serializers.Serializer):
author = serializers.CharField(style={'hide_raw_data': True}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Sometimes we may not want a
HiddenFieldbut just a normal field to be hidden from the browsable API view's raw data input. For example:Idea
Adding a
hide_raw_dataflag to field styles would achieve this:This is just a change in the renderer, so no other side effects of the
HiddenField.Beta Was this translation helpful? Give feedback.
All reactions