Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Enhancement: support naming API fields differently than model fields
  • Loading branch information
TayHobbs committed Apr 22, 2016
commit ddfef58dcbd5e7e072788719a03d0438a47c55fa
9 changes: 6 additions & 3 deletions rest_framework_json_api/renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,13 @@ def extract_included(fields, resource, resource_instance, included_resources):
# For ManyRelatedFields if `related_name` is not set we need to access `foo_set` from `source`
relation_instance_or_manager = getattr(resource_instance, field.child_relation.source)
except AttributeError:
if not hasattr(current_serializer, field.source):
if hasattr(current_serializer, field.source):
serializer_method = getattr(current_serializer, field.source)
relation_instance_or_manager = serializer_method(resource_instance)
elif hasattr(current_serializer.instance, field.source):
relation_instance_or_manager = getattr(current_serializer.instance, field.source)
else:
continue
serializer_method = getattr(current_serializer, field.source)
relation_instance_or_manager = serializer_method(resource_instance)

new_included_resources = [key.replace('%s.' % field_name, '', 1)
for key in included_resources
Expand Down