Created
July 14, 2015 19:49
-
-
Save hello-josh/f67b3487a59ddff9f26b to your computer and use it in GitHub Desktop.
Lazy Iterator to populate WTForms choices
This file contains hidden or 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 LMSInstanceIterator(object): | |
"""Lazy iterator to populate ClientEditForm.lms_instance when rendered""" | |
def __iter__(self): | |
return iter([(instance.key.id(), instance.name) | |
for instance in lmsinstances.query()]) | |
class ClientEditForm(BaseForm): | |
lms_instance = fields.SelectField('LMS Instance', choices=LMSInstanceIterator()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment