Skip to content

Instantly share code, notes, and snippets.

@CharlyJazz
Last active April 1, 2017 13:04
Show Gist options
  • Select an option

  • Save CharlyJazz/0f00796ddbbf1aa57410ebc4a2af20b2 to your computer and use it in GitHub Desktop.

Select an option

Save CharlyJazz/0f00796ddbbf1aa57410ebc4a2af20b2 to your computer and use it in GitHub Desktop.
Choice field for html created with pycountry v.1.5
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