Skip to content

Enhancement: magic field expansion #141

@danihodovic

Description

@danihodovic

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions