drf-dynamic-fields icon indicating copy to clipboard operation
drf-dynamic-fields copied to clipboard

Subclassable get_* filter and omit params

Open nhaggmark opened this issue 7 years ago • 1 comments

Thanks for writing and maintaining this incredibly useful library. I recently ran into a situation where I need to be able to control my serialization dynamically outside of just using URL params. One suggestion that I had for improving this library would be to encapsulate the acquisition of your include and omit lists into it's own method (or set of methods) so that it can be overridden by subclassing (if, perhaps, you wanted to use a different url parameter or even a whole different source, such as the serializer context). That's what I did in my current project.

Cheers!

nhaggmark avatar Feb 08 '18 19:02 nhaggmark

Hey thanks! I'll admit I'm having some trouble following your suggestion. Are you able to give a real life (or realistic) example so I can get it clear in my mind?

would it be something like adding:

def get_omit_params(self):

and

def get_filter_params(self):

rather than what's happening here: https://github.com/dbrgn/drf-dynamic-fields/blob/master/drf_dynamic_fields/init.py#L51

jtrain avatar Feb 09 '18 00:02 jtrain