Modified depth to make it dynamically editable

This commit is contained in:
Samir Otiv 2016-06-02 13:47:03 +05:30
parent cd5772174e
commit ab3892342b

View File

@ -326,6 +326,16 @@ class Serializer(BaseSerializer):
'invalid': _('Invalid data. Expected a dictionary, but got {datatype}.') 'invalid': _('Invalid data. Expected a dictionary, but got {datatype}.')
} }
@property
def depth(self):
if not hasattr(self, '_depth'):
self._depth = getattr(self.Meta, 'depth', 0)
return self._depth
@depth.setter
def depth(self, value):
self._depth = value
@property @property
def fields(self): def fields(self):
""" """
@ -912,7 +922,7 @@ class ModelSerializer(Serializer):
declared_fields = copy.deepcopy(self._declared_fields) declared_fields = copy.deepcopy(self._declared_fields)
model = getattr(self.Meta, 'model') model = getattr(self.Meta, 'model')
depth = getattr(self.Meta, 'depth', 0) depth = self.depth
if depth is not None: if depth is not None:
assert depth >= 0, "'depth' may not be negative." assert depth >= 0, "'depth' may not be negative."