Answer the question
In order to leave comments, you need to log in
How to set custom date format in model form?
Actually, how to make it so that the form has a date format of the form '%d-%m-%Y'
and not the default '%Y-%m-%d'
In settings.py
LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'Asia/Yekaterinburg'
USE_I18N = True
USE_L10N = True
USE_TZ = True
DATE_INPUT_FORMATS = '%d-%m-%Y'
class Person(models.Model):
date_of_births = models.DateField(
"Дата рождения",
blank=False,
null=False,
)
class PersonForm(ModelForm):
class Meta:
model = Person
localized_fields = (
'date_of_births',
)
Answer the question
In order to leave comments, you need to log in
DATE_INPUT_FORMATS must be a list, not a string.DATE_INPUT_FORMATS = ['%d-%m-%Y']
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question