mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Modified depth to make it dynamically editable
This commit is contained in:
parent
cd5772174e
commit
ab3892342b
|
@ -326,6 +326,16 @@ class Serializer(BaseSerializer):
|
|||
'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
|
||||
def fields(self):
|
||||
"""
|
||||
|
@ -912,7 +922,7 @@ class ModelSerializer(Serializer):
|
|||
|
||||
declared_fields = copy.deepcopy(self._declared_fields)
|
||||
model = getattr(self.Meta, 'model')
|
||||
depth = getattr(self.Meta, 'depth', 0)
|
||||
depth = self.depth
|
||||
|
||||
if depth is not None:
|
||||
assert depth >= 0, "'depth' may not be negative."
|
||||
|
|
Loading…
Reference in New Issue
Block a user