mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-02 20:54:42 +03:00
Ensure that realtionship fields '.choices' returns an empty dict when accessed with a read-only field. Closes #2910.
This commit is contained in:
parent
3c57e08f62
commit
bca2ea35df
|
@ -109,12 +109,18 @@ class RelatedField(Field):
|
|||
|
||||
@property
|
||||
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([
|
||||
(
|
||||
six.text_type(self.to_representation(item)),
|
||||
six.text_type(item)
|
||||
)
|
||||
for item in self.get_queryset()
|
||||
for item in queryset
|
||||
])
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user