From 9edf3245b07791d962a950b2dd507b328344613c Mon Sep 17 00:00:00 2001 From: Petros Moisiadis Date: Tue, 5 May 2015 22:31:15 +0300 Subject: [PATCH] Fix for iterating over NoneType in ManyRelatedField's choices() If queryset is not set in the child relation of a ManyRelatedField, choices() will fail trying to iterate over NoneType. This commit fixes this. --- rest_framework/relations.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 00a4a2656..24cb7bdd4 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -375,7 +375,7 @@ class ManyRelatedField(Field): @property def choices(self): - queryset = self.child_relation.queryset + queryset = self.child_relation.queryset or [] iterable = queryset.all() if (hasattr(queryset, 'all')) else queryset items_and_representations = [ (item, self.child_relation.to_representation(item))