In models.py there is a field with type DateTimeField, how to format it? For example, to make it so that in django-admin by default it was displayed not 06.03.2019, but 2019.06.03.?

date = models.DateTimeField(default=datetime.now, verbose_name='Дата и время',) 

    1 answer 1

    Formatting is defined where the date is displayed: in the form or django-admin.

     @admin.register(MyModel) class MyAdmin(admin.ModelAdmin): list_display = ('new_format_date',) def new_format_date(self, obj): return obj.date.strftime('%Y.%b.%d') new_format_date.short_description = 'Отформатированная дата' 
    • Where should I add this piece of code? - The Elusive Joe
    • @ admin.py in admin.py - ChocolateSwan at admin.py