From c3c9a712fa6c8fae6d795b9874e101d15b444b15 Mon Sep 17 00:00:00 2001 From: Venelin Stoykov Date: Mon, 29 Jun 2015 15:35:55 +0300 Subject: [PATCH] Fix ManyRelatedField.choices Use choices from self.child_relation. We don't need to repeat ourself because can get out of sync. --- rest_framework/relations.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index ca39dbade..549aa85c0 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -388,16 +388,4 @@ class ManyRelatedField(Field): @property def choices(self): - queryset = self.child_relation.queryset - iterable = queryset.all() if (hasattr(queryset, 'all')) else queryset - items_and_representations = [ - (item, self.child_relation.to_representation(item)) - for item in iterable - ] - return OrderedDict([ - ( - six.text_type(item_representation), - six.text_type(item) + ' - ' + six.text_type(item_representation) - ) - for item, item_representation in items_and_representations - ]) + return self.child_relation.choices