Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support lazily evaluating expanded serializer class from a function #138

Open
seaworn opened this issue Jan 13, 2024 · 0 comments
Open

Support lazily evaluating expanded serializer class from a function #138

seaworn opened this issue Jan 13, 2024 · 0 comments

Comments

@seaworn
Copy link

seaworn commented Jan 13, 2024

While lazily evaluating the expanded serializer class from a string caters for avoiding circular imports, I need a way to evaluate the class from a function.

I'm using this package together with django-oscar-api which provides it's own helper function (get_api_class) for dynamically loading classes so as to allow overriding the default serializers. As such, I would like to be able to define an expandable field like this:

expandable_fields = {"orders": (lambda: get_api_class("serializers.checkout", "OrderSerializer"), {"many": True})}

I imagine this could provide a lot more flexibility allowing executing some logic to determine the serializer class (or import path), even outside of django-oscar-api

I did some customizing here to get this working and would be happy to open a PR if you're willing to support this in this package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant