rsinger86/drf-flex-fields

Enhancement: magic field expansion

Opened this issue · 0 comments

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