Skip to content
Open
Changes from 2 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
14 changes: 13 additions & 1 deletion syncano/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ManagerDescriptor(object):
def __init__(self, manager):
self.manager = manager

def __get__(self, instance, owner=None):
def __get__(self, instance, owner=None, instance_name=None):
if instance is not None:
raise AttributeError("Manager isn't accessible via {0} instances.".format(owner.__name__))
return self.manager.all()
Expand Down Expand Up @@ -777,10 +777,22 @@ def request(self, method=None, path=None, **request):
raise

if 'next' not in response and not self._template:
self._populate_instance_name(response)
return self.serialize(response)

if isinstance(response, list):
for obj in response['objects']:
self._populate_instance_name(obj)
return response

def _populate_instance_name(self, object):
if 'instance_name' not in self.properties or not isinstance(object, dict):
return
model_fields = ['profile']
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will force us to extend it each time when new ModelField is defined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside that - I've checked this solution and it seems that it's not working.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me. Will refactor and provide test case :)

for field in model_fields:
if field in object:
object[field]['instance_name'] = self.properties['instance_name']

def get_allowed_method(self, *methods):
meta = self.model._meta
allowed_methods = meta.get_endpoint_methods(self.endpoint)
Expand Down