Reputation: 60
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?
Upvotes: 0
Views: 75
Reputation: 1
You can use as below:
person = Person(name="John", country="TR")
person.country.alpha3
>>>"TUR"
Upvotes: 0