How to use alpha3 country code in django model CountryField

40 Views Asked by At

Let's say I have a form that can be filled out by a user with personal details, such as

class PersonForm(ModelFormSansSuffix):
   class Meta:
      model=Person
      fields=["name", "nationality"]
    nationality = forms.ChoiceField(
        label="Country",
        help_text="What country are you from?",
        required=True,
        widget=widgets.CountrySelectWidget(),
        choices=countries,
    )

    name = forms.CharField(
        label="Please enter your name",
        max_length=512,
        required=True,
        widget=forms.TextInput()
    )

I then have a model Person

class Person(models.Model):
      name = models.CharField(max_length=100, null=True, blank=False)
      country = CountryField(blank_label='(select country)', default=None, null=True, blank=True)

By default, country will use the Alpha2 ISO standard (i.e. 'United States' becomes 'US'), but I want it to use the alpha3 standard ('United States' becomes 'USA'). Is there any way I can set the CountryField to use alpha3?

0

There are 0 best solutions below