Drop get_iterable()

This commit is contained in:
Tom Christie 2014-12-10 22:09:24 +00:00
parent ca7b1f6d51
commit 9d3810f313

View File

@ -88,7 +88,7 @@ class RelatedField(Field):
return False return False
def get_attribute(self, instance): def get_attribute(self, instance):
if self.use_pk_only_optimization(): if self.use_pk_only_optimization() and self.source_attrs:
try: try:
# Optimized case, return a mock object only containing the pk attribute. # Optimized case, return a mock object only containing the pk attribute.
instance = get_attribute(instance, self.source_attrs[:-1]) instance = get_attribute(instance, self.source_attrs[:-1])
@ -99,10 +99,6 @@ class RelatedField(Field):
# Standard case, return the object instance. # Standard case, return the object instance.
return get_attribute(instance, self.source_attrs) return get_attribute(instance, self.source_attrs)
def get_iterable(self, instance, source_attrs):
relationship = get_attribute(instance, source_attrs)
return relationship.all() if (hasattr(relationship, 'all')) else relationship
@property @property
def choices(self): def choices(self):
return dict([ return dict([
@ -349,7 +345,8 @@ class ManyRelatedField(Field):
] ]
def get_attribute(self, instance): def get_attribute(self, instance):
return self.child_relation.get_iterable(instance, self.source_attrs) relationship = get_attribute(instance, self.source_attrs)
return relationship.all() if (hasattr(relationship, 'all')) else relationship
def to_representation(self, iterable): def to_representation(self, iterable):
return [ return [