Changed definition of NestedModelSerializer to correct depth handling

This commit is contained in:
JC 2013-04-27 13:23:55 -07:00
parent 3b0fa3ebaa
commit 8cbb715f4c

View File

@ -205,18 +205,6 @@ class BaseSerializer(WritableField):
return ret return ret
#####
# Field methods - used when the serializer class is itself used as a field.
def initialize(self, parent, field_name):
"""
Same behaviour as usual Field, except that we need to keep track
of state so that we can deal with handling maximum depth.
"""
super(BaseSerializer, self).initialize(parent, field_name)
if parent.opts.depth:
self.opts.depth = parent.opts.depth - 1
##### #####
# Methods to convert or revert from objects <--> primitive representations. # Methods to convert or revert from objects <--> primitive representations.
@ -619,6 +607,8 @@ class ModelSerializer(Serializer):
class NestedModelSerializer(ModelSerializer): class NestedModelSerializer(ModelSerializer):
class Meta: class Meta:
model = model_field.rel.to model = model_field.rel.to
depth = self.opts.depth - 1
return NestedModelSerializer() return NestedModelSerializer()
def get_related_field(self, model_field, to_many=False): def get_related_field(self, model_field, to_many=False):