This commit is contained in:
Warren Jin 2015-01-28 10:20:06 -05:00
parent 672df63599
commit a63b9fde2e
2 changed files with 4 additions and 21 deletions

View File

@ -1294,24 +1294,6 @@ class RecursiveField(Field):
next = RecursiveField(allow_null=True)
"""
# Implementation notes
#
# Only use __getattribute__ to forward the bound methods. Stop short of
# forwarding all attributes for the following reasons:
# - if you forward the __class__ attribute then deepcopy will give you back
# the wrong class
# - if you forward the fields attribute then __repr__ will enter into an
# infinite recursion
# - who knows what other infinite recursions are possible
#
# We only forward bound methods, but there are some attributes that must be
# accessible on both the RecursiveField and the proxied serializer, namely:
# field_name, read_only, default, source_attrs, write_attrs, source. As far
# as I can tell, the cleanest way to make these fields availabe without
# piecemeal forwarding them through __getattribute__ is to call bind and
# __init__ on both the RecursiveField and the proxied field using the exact
# same arguments.
def __init__(self, to='self', to_module=None, **kwargs):
self.to = to
self.to_module = to_module

View File

@ -1,5 +1,6 @@
from rest_framework import serializers
class LinkSerializer(serializers.Serializer):
name = serializers.CharField(max_length=25)
next = serializers.RecursiveField(required=False, allow_null=True)