3
3
from django .utils .translation import ugettext_lazy as _
4
4
from rest_framework .exceptions import ParseError
5
5
from rest_framework .serializers import * # noqa: F403
6
+ from rest_framework .fields import Field
6
7
7
8
from rest_framework_json_api .helpers import ResourceIdentifier
8
9
from rest_framework_json_api .exceptions import Conflict
16
17
)
17
18
18
19
19
- class ResourceIdentifierSerializer ( Serializer ):
20
+ class ResourceIdentifierField ( Field ):
20
21
""" Serializer for 'pointers' to resources in the JSON document """
21
22
id = CharField (max_length = 64 )
22
23
type = CharField (max_length = 256 )
@@ -27,11 +28,10 @@ class ResourceIdentifierSerializer(Serializer):
27
28
28
29
def __init__ (self , * args , ** kwargs ):
29
30
self .expected_types = kwargs .pop ('expected_types' , None )
30
- super (ResourceIdentifierSerializer , self ).__init__ (* args , ** kwargs )
31
+ super (ResourceIdentifierField , self ).__init__ (* args , ** kwargs )
31
32
32
33
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' ])
35
35
36
36
def validate_type (self , resource_type ):
37
37
if self .expected_types is not None and resource_type not in self .expected_types :
0 commit comments