Skip to content

Conversation

@leifurhauks
Copy link

in the included_serializers class attribute, classes may be specified as a
string containing the absolute python path for the desired class. Thus, the
values in included_serializers may be a class, a string with the python path
of the desired class, or 'self' to specify the class of the current serializer.

for example:

from rest_framework_json_api import serializers
from rest_framework_json_api.relations import ResourceRelatedField

from myapp.models import Thing
from anotherapp.serializers import CategorySerializer

class ThingSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Thing
        serializer_related_field = ResourceRelatedField

    included_serializers = {
        'category': CategorySerializer,
        'accessories': 'myapp.serializers.AccessorySerializer',
        'related_things': 'self'  # ThingSerializer
    }

Leifur Halldor Asgeirsson added 2 commits October 8, 2015 15:36
in the included_serializers class attribute, classes may be specified as a
string containing the absolute python path for the desired class. Thus, the
values in included_serializers may be a class, a string with the python path
of the desired class, or 'self' to specify the class of the current serializer.

for example:

```python
from rest_framework_json_api import serializers
from rest_framework_json_api.relations import ResourceRelatedField

from myapp.models import Thing
from anotherapp.serializers import CategorySerializer

class ThingSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Thing
        serializer_related_field = ResourceRelatedField

    included_serializers = {
        'category': CategorySerializer,
        'accessories': 'myapp.serializers.AccessorySerializer',
        'related_things': 'self'  # ThingSerializer
    }
```
jsenecal added a commit that referenced this pull request Oct 8, 2015
included_serializers may be specified with strings
@jsenecal jsenecal merged commit a09c200 into django-json-api:develop Oct 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants