mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Changed definition of NestedModelSerializer to correct depth handling
This commit is contained in:
parent
3b0fa3ebaa
commit
8cbb715f4c
|
@ -205,18 +205,6 @@ class BaseSerializer(WritableField):
|
|||
|
||||
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.
|
||||
|
||||
|
@ -619,6 +607,8 @@ class ModelSerializer(Serializer):
|
|||
class NestedModelSerializer(ModelSerializer):
|
||||
class Meta:
|
||||
model = model_field.rel.to
|
||||
depth = self.opts.depth - 1
|
||||
|
||||
return NestedModelSerializer()
|
||||
|
||||
def get_related_field(self, model_field, to_many=False):
|
||||
|
|
Loading…
Reference in New Issue
Block a user