mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 03:50:11 +03:00
Added hyperlinking support to nested fields.
Overrode the base get_nested_fields() method in ModelSerializer, to allow for hyperlinking in nested children of the HyperlinkingModelSerializer.
This commit is contained in:
parent
69b8ec4ebd
commit
afd63074dd
|
@ -1107,3 +1107,16 @@ class HyperlinkedModelSerializer(ModelSerializer):
|
|||
'model_name': model_meta.object_name.lower()
|
||||
}
|
||||
return self._default_view_name % format_kwargs
|
||||
|
||||
def get_nested_field(self, model_field, related_model, to_many):
|
||||
"""
|
||||
Creates a default instance of a hyperlinked nested relational field.
|
||||
|
||||
Note that model_field will be `None` for reverse relationships.
|
||||
"""
|
||||
class NestedHyperlinkedModelSerializer(HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = related_model
|
||||
depth = self.opts.depth - 1
|
||||
|
||||
return NestedHyperlinkedModelSerializer(many=to_many)
|
||||
|
|
Loading…
Reference in New Issue
Block a user