mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-06 13:30:12 +03:00
minor cleanup
This commit is contained in:
parent
67ed7d7933
commit
a596ace793
|
@ -1302,8 +1302,6 @@ class RecursiveField(Field):
|
||||||
super(RecursiveField, self).__init__(**field_kwargs)
|
super(RecursiveField, self).__init__(**field_kwargs)
|
||||||
|
|
||||||
def bind(self, field_name, parent):
|
def bind(self, field_name, parent):
|
||||||
real_dict = object.__getattribute__(self, '__dict__')
|
|
||||||
|
|
||||||
if hasattr(parent, 'child') and parent.child is self:
|
if hasattr(parent, 'child') and parent.child is self:
|
||||||
proxy_class = parent.parent.__class__
|
proxy_class = parent.parent.__class__
|
||||||
else:
|
else:
|
||||||
|
@ -1311,21 +1309,24 @@ class RecursiveField(Field):
|
||||||
|
|
||||||
proxy = proxy_class(**self._kwargs)
|
proxy = proxy_class(**self._kwargs)
|
||||||
proxy.bind(field_name, parent)
|
proxy.bind(field_name, parent)
|
||||||
real_dict['proxy'] = proxy
|
self.proxy = proxy
|
||||||
|
|
||||||
def __getattribute__(self, name):
|
def __getattribute__(self, name):
|
||||||
real_dict = object.__getattribute__(self, '__dict__')
|
d = object.__getattribute__(self, '__dict__')
|
||||||
if 'proxy' in real_dict and name != 'fields' and not (name.startswith('__') and name.endswith('__')):
|
|
||||||
return object.__getattribute__(real_dict['proxy'], name)
|
# do not alias the fields parameter to prevent __repr__ from
|
||||||
|
# infinite recursion
|
||||||
|
if 'proxy' in d and name != 'fields' and name != 'proxy' and \
|
||||||
|
not (name.startswith('__') and name.endswith('__')):
|
||||||
|
return object.__getattribute__(d['proxy'], name)
|
||||||
else:
|
else:
|
||||||
return object.__getattribute__(self, name)
|
return object.__getattribute__(self, name)
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
real_dict = object.__getattribute__(self, '__dict__')
|
if 'proxy' in self.__dict__ and name is not 'proxy':
|
||||||
if 'proxy' in real_dict:
|
setattr(self.__dict__['proxy'], name, value)
|
||||||
setattr(real_dict['proxy'], name, value)
|
|
||||||
else:
|
else:
|
||||||
real_dict[name] = value
|
self.__dict__[name] = value
|
||||||
|
|
||||||
|
|
||||||
class SerializerMethodField(Field):
|
class SerializerMethodField(Field):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user