I have a model, like this:
class Cert(models.Model):
COUNTY_CHOICES = (
('Choice1', 'Choice1'),
('Choice2', 'Choice2'),
)
someField = models.CharField(max_length=12, unique=True)
county = models.CharField(max_length=10, choices=COUNTY_CHOICES)
Then I have a form, like this:
class SearchForm(forms.Form):
someField = forms.CharField(max_length=12, required=False)
county = forms.ChoiceField(choices=Cert.COUNTY_CHOICES, required=False)
I want my search form to allow a “blank” or “all” option, but I don’t want my model to allow it. Is there a way to do this or do I have to create another list of CHOICES? I tried making it not required in the form, and I tried adding an “initial” setting, neither of which solved my problem.
Build another choices tuple from
COUNTY_CHOICES, and use that in your form.