Closed
Description
Hey. I'm having problems with included. Here is my code:
serializers.py
class PatientSerializer(serializers.ModelSerializer):
class Meta:
model = models.Patient
class AppealSerializer(serializers.ModelSerializer):
patient = PatientSerializer(
read_only=True
)
class Meta:
model = models.Appeal
class JSONAPIMeta:
included_resources = ['patient']
views.py
class AppealsListAPI(viewsets.ModelViewSet):
serializer_class = AppealSerializer
parser_classes = (JSONParser,)
def get_queryset(self):
return Appeal.objects.filter(parent=None).exclude(appeal_number='')
urls.py
url(r'^api/appeals/', views.AppealsListAPI.as_view({ 'get': 'list' }))
So I expect Patient model be serialized and included under included key as per JSON API.
But this code from rest_framework_json_api/utils.py:
def get_default_included_resources_from_serializer(serializer):
try:
return list(serializer.JSONAPIMeta.included_resources) # serializer.__class__ is ListSerializer here, and there is no JSONAPIMeta
except AttributeError:
return []
always returns an empty array (because of the reason stated in comment), hence included is not populated in the resulting payload. Is there a way to overcome this issue or it's a bug? Or maybe there is something wrong with my code? Thanks.
Metadata
Metadata
Assignees
Labels
No labels