Search code examples
djangodjango-admin

Django - How to show Full name of the Month in Django Admin Panel


I want to show Full month (like April or September) in Django Admin Panel. But it keeps show me first 3 letter of the month or a number. Is there any way to do make it show full month on Admin Panel? Thanks!

PS: The date format I want is like 04 December 2023

enter image description here enter image description here

admin.py

@admin.register(Todo)
class TodoAdmin(admin.ModelAdmin):
    list_display = ("id","title","due_date",)
    list_display_links = ("title",)

    def due_date(self,obj):
        return obj.date.strftime("%d %B %Y")

models.py

class Todo(models.Model):
  title = models.CharField(max_length=250)
  due_date = models.DateField()

  def __str__(self):
      return self.title

settings.py

LANGUAGE_CODE = 'en-gb'
TIME_ZONE = 'Asia/Jakarta'
USE_I18N = True
USE_TZ = True

Python version

3.11.1

Django version

4.2

Solution

  • I found out that due_date field cannot be overriden with the same function name. I have to change it to different function name, and put description and django admin default filter functionality manually back

    admin.py

    @admin.register(Todo)
    class AdminTodo(admin.ModelAdmin):  
        list_display = ('id','title','admin_due_date',)
        list_display_links = ('title',)
    
        # display table header as due_date instead of admin_due_date
        @admin.display(description='due_date')
        def admin_due_date(self,obj):
           return obj.due_date.strftime("%d %B %Y")
    
        # set django admin filter functionality back
        admin_due_date.admin_order_field = 'due_date'