S
S
sazhyk2016-11-23 18:39:58
Django
sazhyk, 2016-11-23 18:39:58

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'

In models.py
class Person(models.Model):
    date_of_births = models.DateField(
        "Дата рождения",
        blank=False,
        null=False,
    )

In forms.py
class PersonForm(ModelForm):

    class Meta:
        model = Person
        localized_fields = (
            'date_of_births',
        )

It was read. And this too. Googled. Everyone sends two links to it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2016-11-23
@sazhyk

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 question

Ask a Question

731 491 924 answers to any question