Reputation: 64054
In my models.py I have the following CharField
class Method1(models.Model):
inputfile_param = models.FileField()
clustering_method_param = models.CharField(max_length=20,
default='ward', blank=True, choices=(
('complete', 'Complete linkage'),
('average','Average linkage'),
('ward','Ward'),))
How do I remove the default --------- choice from CharField?
I tried inserting empty_label=None
but not working.
And I cannot remove blank=True
because it will prevent
FileField()
failed to capture the uploaded file.
My forms.py looks like this:
class Method1ClusteringForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(Method1ClusteringForm, self).__init__(*args, **kwargs)
Upvotes: 2
Views: 1455
Reputation: 895
I have found this which may be the solution for you, too.
Try:
from django.forms import ModelForm
from django import forms as forms
class Method1ClusteringForm(ModelForm):
clustering_method_param = forms.forms.TypedChoiceField(
required=True,
initial = 'ward',
choices = (
('complete', 'Complete linkage'),
('average','Average linkage'),
('ward','Ward'),)
)
class Meta:
model = Method1
fields = ('inputfile_param', 'clustering_method_param',)
Upvotes: 2