Last active
April 1, 2017 13:04
-
-
Save CharlyJazz/0f00796ddbbf1aa57410ebc4a2af20b2 to your computer and use it in GitHub Desktop.
Choice field for html created with pycountry v.1.5
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 Country_list(list): | |
| """'create choice for html form""" | |
| def __init__(self): | |
| self.lista_alpha = [] | |
| self.lista_name = [] | |
| self.choice = None | |
| def create_choices(self): | |
| t = list(pycountry.countries) | |
| for country in t: | |
| self.lista_alpha.append(country.alpha2) | |
| self.lista_name.append(country.name) | |
| self.choice = zip(self.lista_alpha, self.lista_name) | |
| return self.choice | |
| countries = Country_list() | |
| choices_class = countries.create_choices() | |
| class PersonalForm(Form): | |
| country = SelectField('Country', choices=choices_class) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment