Commit 995abd3e authored by bakatrouble's avatar bakatrouble

Correctly process sqlalchemy_utils ChoiceType fields

parent 58e9ea7a
......@@ -117,6 +117,13 @@ class Select2Field(fields.SelectField):
self.allow_blank = allow_blank
self.blank_text = blank_text or ' '
try:
from sqlalchemy_utils.types.choice import Choice
except ImportError:
class Choice(object):
pass
self.choice_cls = Choice
def iter_choices(self):
if self.allow_blank:
yield (u'__None', self.blank_text, self.data is None)
......@@ -129,7 +136,10 @@ class Select2Field(fields.SelectField):
self.data = None
else:
try:
self.data = self.coerce(value)
if isinstance(value, self.choice_cls):
self.data = self.coerce(value.code)
else:
self.data = self.coerce(value)
except (ValueError, TypeError):
self.data = None
......
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