Cannot set Default country
sharad740 opened this issue · comments
In forms.py
from django_countries.widgets import CountrySelectWidget
from django import forms
from enroll.models import Person
class PersonForm(forms.ModelForm):
class Meta:
model = Person
fields = ('name', 'country')
widgets = {'country': CountrySelectWidget()}
Returns : Select Country by default
In models.py
from django.db import models
from django_countries.fields import CountryField
class Person(models.Model):
name = models.CharField(max_length=100,)
country = CountryField(blank_label='(select country)',blank=True)
def __str__(self):
return self.name
Setting a default on the CountryField removes the blank choice.
See favourite_country
example here:
django-countries/django_countries/tests/models.py
Lines 7 to 14 in 9d433ad
Tested here:
django-countries/django_countries/tests/test_fields.py
Lines 622 to 626 in 9d433ad