Created
March 16, 2011 15:27
-
-
Save ksamuel/872662 to your computer and use it in GitHub Desktop.
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
# create a generator | |
# 'pairs' now hold an object that generates ((k, v), (k, v), ) it passed into a for loop | |
pairs = ((f.slug, f.name) for f in FacilityType.objects.all())) | |
# tuple(pairs) actually run the generator and turn the result into a tuple | |
# if the tuple is empty, 'or' replace it with a default value to avoid an empty choice | |
# of course this is a result you don't want in prod, but it's handy for dev with an empty DB | |
# if you want to make that production friendly, you must be sure to forbid none as a value | |
# on the validation form | |
properties_feature_type_choices = tuple(pairs) or (('none', 'None')) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment