rest_framework_json_api.relations module¶
-
class
rest_framework_json_api.relations.
SkipDataMixin
(*args, **kwargs)¶ Bases:
object
This workaround skips “data” rendering for relationships in order to save some sql queries and improve performance
-
get_attribute
(instance)¶
-
to_representation
(*args)¶
-
-
class
rest_framework_json_api.relations.
ManyRelatedFieldWithNoData
(*args, **kwargs)¶ Bases:
rest_framework_json_api.relations.SkipDataMixin
,rest_framework.relations.ManyRelatedField
-
class
rest_framework_json_api.relations.
HyperlinkedMixin
(self_link_view_name=None, related_link_view_name=None, **kwargs)¶ Bases:
object
-
self_link_view_name
= None¶
-
get_url
(name, view_name, kwargs, request)¶ Given a name, view name and kwargs, return the URL that hyperlinks to the object.
May raise a NoReverseMatch if the view_name and lookup_field attributes are not configured to correctly match the URL conf.
-
get_links
(obj=None, lookup_field='pk')¶
-
-
class
rest_framework_json_api.relations.
HyperlinkedRelatedField
(self_link_view_name=None, related_link_view_name=None, **kwargs)¶ Bases:
rest_framework_json_api.relations.HyperlinkedMixin
,rest_framework_json_api.relations.SkipDataMixin
,rest_framework.relations.RelatedField
-
classmethod
many_init
(*args, **kwargs)¶ This method handles creating a parent ManyRelatedField instance when the many=True keyword argument is passed.
Typically you won’t need to override this method.
Note that we’re over-cautious in passing most arguments to both parent and child classes in order to try to cover the general case. If you’re overriding this method you’ll probably want something much simpler, eg:
@classmethod def many_init(cls, *args, **kwargs): kwargs['child'] = cls() return CustomManyRelatedField(*args, **kwargs)
-
classmethod
-
class
rest_framework_json_api.relations.
ResourceRelatedField
(**kwargs)¶ Bases:
rest_framework_json_api.relations.HyperlinkedMixin
,rest_framework.relations.PrimaryKeyRelatedField
-
self_link_view_name
= None¶
-
default_error_messages
= {'does_not_exist': 'Invalid pk "{pk_value}" - object does not exist.', 'incorrect_relation_type': 'Incorrect relation type. Expected {relation_type}, received {received_type}.', 'incorrect_type': 'Incorrect type. Expected resource identifier object, received {data_type}.', 'missing_id': "Invalid resource identifier object: missing 'id' attribute", 'missing_type': "Invalid resource identifier object: missing 'type' attribute", 'no_match': 'Invalid hyperlink - No URL match.', 'required': 'This field is required.'}¶
-
use_pk_only_optimization
()¶
-
conflict
(key, **kwargs)¶ A helper method that simply raises a validation error.
-
to_internal_value
(data)¶
-
to_representation
(value)¶
-
get_resource_type_from_included_serializer
()¶ Check to see it this resource has a different resource_name when included and return that name, or None
-
get_parent_serializer
()¶
-
is_serializer
(candidate)¶
-
get_choices
(cutoff=None)¶
-
-
class
rest_framework_json_api.relations.
PolymorphicResourceRelatedField
(polymorphic_serializer, *args, **kwargs)¶ Bases:
rest_framework_json_api.relations.ResourceRelatedField
Inform DRF that the relation must be considered polymorphic. Takes a polymorphic_serializer as the first positional argument to retrieve then validate the accepted types set.
-
default_error_messages
= {'does_not_exist': 'Invalid pk "{pk_value}" - object does not exist.', 'incorrect_relation_type': 'Incorrect relation type. Expected one of [{relation_type}], received {received_type}.', 'incorrect_type': 'Incorrect type. Expected resource identifier object, received {data_type}.', 'missing_id': "Invalid resource identifier object: missing 'id' attribute", 'missing_type': "Invalid resource identifier object: missing 'type' attribute", 'no_match': 'Invalid hyperlink - No URL match.', 'required': 'This field is required.'}¶
-
use_pk_only_optimization
()¶
-
to_internal_value
(data)¶
-
-
class
rest_framework_json_api.relations.
SerializerMethodResourceRelatedField
(child_relation=None, *args, **kwargs)¶ Bases:
rest_framework_json_api.relations.ResourceRelatedField
Allows us to use serializer method RelatedFields with return querysets
-
classmethod
many_init
(*args, **kwargs)¶
-
get_attribute
(instance)¶
-
to_representation
(value)¶
-
classmethod
-
class
rest_framework_json_api.relations.
SerializerMethodHyperlinkedRelatedField
(*args, **kwargs)¶ Bases:
rest_framework_json_api.relations.SkipDataMixin
,rest_framework_json_api.relations.SerializerMethodResourceRelatedField