Created
June 25, 2013 21:07
-
-
Save doobeh/5862407 to your computer and use it in GitHub Desktop.
Extended QuerySelectField to allow SQLAlchemy objects to be passed in as default avalues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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