drf-action-serializer icon indicating copy to clipboard operation
drf-action-serializer copied to clipboard

Add depth to the options in the action_fields

Open dafful-dev opened this issue 3 years ago • 2 comments

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 }}

dafful-dev avatar Dec 11 '21 10:12 dafful-dev

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)

dafful-dev avatar Dec 11 '21 17:12 dafful-dev

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.

gregschmit avatar Dec 15 '21 19:12 gregschmit