Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

included_resources + ListSerializer #291

Closed
@pavloo

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /