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

Commit a765e20

Browse files
Convert ResourceIdentifier to field
1 parent af54109 commit a765e20

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

‎rest_framework_json_api/serializers.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.utils.translation import ugettext_lazy as _
44
from rest_framework.exceptions import ParseError
55
from rest_framework.serializers import * # noqa: F403
6+
from rest_framework.fields import Field
67

78
from rest_framework_json_api.helpers import ResourceIdentifier
89
from rest_framework_json_api.exceptions import Conflict
@@ -16,7 +17,7 @@
1617
)
1718

1819

19-
class ResourceIdentifierSerializer(Serializer):
20+
class ResourceIdentifierField(Field):
2021
""" Serializer for 'pointers' to resources in the JSON document """
2122
id = CharField(max_length=64)
2223
type = CharField(max_length=256)
@@ -27,11 +28,10 @@ class ResourceIdentifierSerializer(Serializer):
2728

2829
def __init__(self, *args, **kwargs):
2930
self.expected_types = kwargs.pop('expected_types', None)
30-
super(ResourceIdentifierSerializer, self).__init__(*args, **kwargs)
31+
super(ResourceIdentifierField, self).__init__(*args, **kwargs)
3132

3233
def to_internal_value(self, data):
33-
ret = super(ResourceIdentifierSerializer, self).to_internal_value(data)
34-
return ResourceIdentifier(ret['type'], ret['id'])
34+
return ResourceIdentifier(data['type'], data['id'])
3535

3636
def validate_type(self, resource_type):
3737
if self.expected_types is not None and resource_type not in self.expected_types:

0 commit comments

Comments
(0)

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