Django: format DateField inherited by the model
I have a model with a DateField
:
class Info(models.Model):
userprofile = models.OneToOneField(UserProfile, primary_key=True)
birth_date = models.DateField()
and i generate a form from it:
class SecondStepForm(ModelForm):
class Meta:
model = Info
exclude = ('userprofile',)
The problem is that i want to format the date input. I know it is possible with forms.DateField
:
开发者_StackOverflow社区 birth_date = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'), input_formats=('%d/%m/%Y',))
but how to tell django that it should make a form from the model except for the date field where it should use forms.DateField
?
You're there already. Just put that birth_date
definition at the top level of the form, before the Meta class, and it will override the default field.
精彩评论