Skip to content

Commit

Permalink
Do not apply filter to nested serializers
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Apr 7, 2017
1 parent 806e260 commit b844078
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions drf_dynamic_fields/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ def fields(self):
"""
Filters the fields according to the `fields` query parameter.
a blank `fields` parameter (?fields) will remove all fields.
not passing `fields` will pass all fields
individual fields are comma separated (?fields=id,name,url,email)
A blank `fields` parameter (?fields) will remove all fields. Not
passing `fields` will pass all fields individual fields are comma
separated (?fields=id,name,url,email).
"""
fields = super(DynamicFieldsMixin, self).fields

if not hasattr(self, '_context'):
# we are being called before a request cycle.
# We are being called before a request cycle
return fields

# Only filter if this is the root serializer, or if the parent is the
# root serializer with many=True
is_root = self.root == self
parent_is_list_root = self.parent == self.root and getattr(self.parent, 'many', False)
if not (is_root or parent_is_list_root):
return fields

try:
Expand Down

0 comments on commit b844078

Please sign in to comment.