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:
sjb933 2014-02-12 20:25:10 -06:00
parent 69b8ec4ebd
commit afd63074dd

View File

@ -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)