ModelMultipleChoiceField: Don't try to iterate over model instances (#18172) #601

wants to merge 2 commits into

3 participants


Test case included.

I've decided to go with the hasattr(value, '_meta') test as it's already used by other fields.

@charettes charettes commented on the diff Dec 19, 2012
@@ -1033,6 +1033,8 @@ def clean(self, value):
return qs
def prepare_value(self, value):
- if hasattr(value, '__iter__') and not isinstance(value, six.text_type):
+ if (hasattr(value, '__iter__') and
+ not isinstance(value, six.text_type) and
+ not hasattr(value, '_meta')):
charettes Dec 19, 2012 Django member

What about not isinstance(value, models.Model)? Maybe duck-typing is enough...

Django member

Merged in manually - the '_meta' check seems OK, there is already one similar check in the forms/

@akaariai akaariai closed this Dec 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment