Allow omit query_param and omit keyword
Closed this issue · 1 comments
robertcarr commented
I would like to specify some fields to omit when I initialize the serializer and also allow the API request query_param to omit extrfa fields. Right now it's either or but merging the two would be nice. Also the same for fields, possibly.
For example:
This should return all the fields except password &email. Right now, it will only omit password.
FlexSerializer(data=request.data, omit=['password'])
GET /api/?omit=email
def __init__(self, *args, **kwargs):
expand = list(kwargs.pop("expand", []))
fields = list(kwargs.pop("fields", []))
omit = list(kwargs.pop("omit", []))
super(FlexFieldsSerializerMixin, self).__init__(*args, **kwargs)
self.expanded_fields = []
self._flex_fields_applied = False
self._flex_options = {
"expand": (
expand
if len(expand) > 0
else self._get_permitted_expands_from_query_param()
),
"fields": (
fields if len(fields) > 0 else self._get_query_param_value("fields")
),
"omit": omit if len(omit) > 0 else self._get_query_param_value("omit"),
}
rsinger86 commented
This seems like a straightforward change to the source code, but I'm concerned that it may cause unexpected behavior in existing projects.