Skip to content

Instantly share code, notes, and snippets.

@doobeh doobeh/forms.py
Created Jun 25, 2013

Embed
What would you like to do?
Extended QuerySelectField to allow SQLAlchemy objects to be passed in as default avalues
class QuerySelectFieldCustom(QuerySelectField):
"""Extended to allow default checked items
Probably a much more obvious way to do this...
"""
selected = None
def iter_choices(self):
if self.allow_blank:
yield (u'__None', self.blank_text, self.data is None)
for pk, obj in self._get_object_list():
if self.selected is not None and self.selected.id == obj.id:
yield (pk, self.get_label(obj), True)
else:
yield (pk, self.get_label(obj), obj in self.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.