Skip to content

allow manually specifying a parent if auto resolution won't work #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions rest_framework_recursive/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,24 @@ def proxied(self):

if hasattr(parent, 'child') and parent.child is self:
# RecursiveField nested inside of a ListField
parent_class = parent.parent.__class__
resolved_parent = parent.parent
else:
# RecursiveField directly inside a Serializer
parent_class = parent.__class__

assert issubclass(parent_class, BaseSerializer)
resolved_parent = parent

if self.to is None:
proxied_class = parent_class
assert isinstance(resolved_parent, BaseSerializer)
proxied_class = resolved_parent.__class__
else:
try:
module_name, class_name = self.to.rsplit('.', 1)
except ValueError:
module_name, class_name = parent_class.__module__, self.to
assert resolved_parent, (
'Could not automatically determine a parent '
'class, specify a dotted to= path'
)
module_name = resolved_parent.__class__.__module__
class_name = self.to

try:
proxied_class = getattr(
Expand Down