Skip to content

Instantly share code, notes, and snippets.

@hello-josh
Created July 14, 2015 19:49
Show Gist options
  • Save hello-josh/f67b3487a59ddff9f26b to your computer and use it in GitHub Desktop.
Save hello-josh/f67b3487a59ddff9f26b to your computer and use it in GitHub Desktop.
Lazy Iterator to populate WTForms choices
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