Commit efdf1e88 by Tom Christie

Ensure that realtionship fields '.choices' returns an empty dict when accessed…

Ensure that realtionship fields '.choices' returns an empty dict when accessed with a read-only field.
parent 46836142
...@@ -109,12 +109,18 @@ class RelatedField(Field): ...@@ -109,12 +109,18 @@ class RelatedField(Field):
@property @property
def choices(self): def choices(self):
queryset = self.get_queryset()
if queryset is None:
# Ensure that field.choices returns something sensible
# even when accessed with a read-only field.
return {}
return OrderedDict([ return OrderedDict([
( (
six.text_type(self.to_representation(item)), six.text_type(self.to_representation(item)),
six.text_type(item) six.text_type(item)
) )
for item in self.get_queryset() for item in queryset
]) ])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment