drf-action-serializer
drf-action-serializer copied to clipboard
Add depth to the options in the action_fields
The depth Meta fields enables relationship expansion. I believe adding this field will be an amazing addition to this awesome library. I use this library a lot. However I found myself repeating Serializers because of this.
Essentially I wanted to be able to do something like this"
action_fields = {"list": {"fields": ("id", "name","product"), "depth": 2 }}
i tried this:
def build_field(self, field_name, info, model_class, nested_depth):
action_config = self.get_action_config()
if action_config and "depth" in action_config:
depth = action_config.get("depth", None)
else:
depth = nested_depth
return super().build_field(field_name, info, model_class, depth)
I like this idea; a PR is welcome, however this weekend I might be able to tackle this. Some of the methods I overrode from DRF, so I probably should just check the diff and apply similar changes to the latest DRF code so that we inherit some of the features that didn't exist when I originally wrote this.