Closed
Description
I would like to use the SerializerMethodResourceRelatedField to get multiple models through a function. It works when the function returns only a single model object, but not with a list of objects.
If I try to use the many=True param, the call of the defined function fails with the error message:
'Entry' object has no attribute 'get_hot_entries'
It seems the get_attribute function of the SerializerMethodResourceRelatedField is never called, when passing many=True.
Example:
class EntrySerializer(serializers.ModelSerializer):
hot_entries = relations.SerializerMethodResourceRelatedField(
source='get_hot_entries',
many=True,
read_only=True
)
included_serializers = {
'hot_entries': 'EntrySerializer'
}
def get_hot_entries(self, obj):
return Entry.objects.filter(hot=True)
class Meta:
model = Entry
I'm using django-rest-framework-json-api v2.0.0-beta.2
Metadata
Metadata
Assignees
Labels
No labels