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

Enhancement: magic field expansion #141

Open
danihodovic opened this issue May 23, 2024 · 0 comments
Open

Enhancement: magic field expansion #141

danihodovic opened this issue May 23, 2024 · 0 comments

Comments

@danihodovic
Copy link

This is a great library and a recent discovery of mine. I found declaring expandable_fields tedious and wanted to automatically discover expandable_fields based on model relationships. I came up with the snippet below in one of my projects. I was wondering if you're open to a pull-request where we add the functionality?

We could use the __all__ convention, common in DRF, to make all related fields expandable.

from myapp.api.serializers.utils import MagicFlexFieldsModelSerializer

class UserSerializer(MagicFlexFieldsModelSerializer):
    class Meta:
        model = User
        fields = [
            "id",
            "name",
        ]
        expandable_fields = "__all__"

https://django.wtf/blog/graphql-like-features-in-django-rest-framework/#magically-discovering-expandable_fields

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