evenicoulddoit / django-rest-framework-serializer-extensions

Extensions to help DRY up Django Rest Framework serializers
Other
247 stars 23 forks source link

This just doesn't work #40

Closed mmichealjroberts closed 4 years ago

mmichealjroberts commented 4 years ago

I've followed all of the reproducable steps in the documentation, and my fields are now excluded:

class DomainSerializer(
    SerializerExtensionsMixin,
    serializers.ModelSerializer
):
    # disciplines = BranchSerializer(many=True)

    # dataset_count = serializers.SerializerMethodField()

    class Meta:
        model = Domain
        fields = [
            'uuid', 'id', 'name', 'slug', 'thumbnail',
        ]
        expandable_fields = dict(
            dataset_count=serializers.SerializerMethodField,
            disciplines=dict(
                serializer=BranchSerializer,
                many=True
            )
        )

    def get_dataset_count(self, obj):
        return obj.datasets.all().count()

And now in the listing API viewset:

class DomainViewset(
    SerializerExtensionsAPIViewMixin,
    ListAPIView
):
    queryset = Domain.objects.all()
    serializer_class = DomainSerializer
    extensions_auto_optimize = True

When hitting the endpoint, it lists, minus the expandable fields.

What am I doing wrong? What can I do to help improve the documentation?

evenicoulddoit commented 4 years ago

What do you mean it doesn't work? When you hit the endpoint it shouldn't do anything by default given the above. Could you be more specific. Also, what have you tried?

mmichealjroberts commented 4 years ago

@evenicoulddoit So how to we use it then? I've followed the example and replicated the steps as closely as possible, no errors thrown, it just lists the Domain models, minus the two fields I have tried to work with the expandable_fields value in the Serialzier...

evenicoulddoit commented 4 years ago

Hi @michealjroberts - I'm going to close this for now and point you towards the examples in the README. The full documentation may also help. If you have a specific issue, please let me know.