1

Am new in Django so any help will be appreciated, I have a model that contain 3 fields , one of them is date , i want to change the display of date in Django Admin(now it's 2022-05-20 but i want it to be 20-05-2022).

How i can do that please !

this is my models.py:

class reports(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    project_name = models.CharField(verbose_name="Project name", max_length=60)
    date = models.DateField(verbose_name="Date", default=date.today)
    def __str__(self):
        return str(self.user)

and this is my admin.py:

class reportsAdmin(admin.ModelAdmin):
    @admin.display(description='date')
    def admin_date(self, obj):
        return obj.date.strftime('%d-%m-%Y')

    list_display = ('user', 'project_name', 'admin_date')
admin.site.register(reports, reportsAdmin)

and in my settings.py:

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = False
USE_TZ = True

but nothing work , still display to me in format 2022-05-20(year-month-date).

How i can correctly change the format date to be date-month-year in Django admin???

enter image description here

1 Answers1

0

Your code does convert the date to the format you want in the list page where all the reports are displayed. I don't think that what you want can be accomplished with the reportsAdmin class. What you need is to change the input element that can maybe be done by changing the admin templates. But I am not sure that it can be done at all because that is how the input works for dates.

Edit: I found this question that 3rd and 2nd answers mention some ways you can accomplish this in HTML Is there any way to change input type="date" format?