Skip to content

Instantly share code, notes, and snippets.

@bee-keeper
Created August 20, 2014 11:27
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bee-keeper/e9c69e757b529fcffeda to your computer and use it in GitHub Desktop.
Save bee-keeper/e9c69e757b529fcffeda to your computer and use it in GitHub Desktop.
Display only month, year in django admin and django list_display
#models.py
class SomeClass(models.Model):
date = models.DateField()
#forms.py
date = forms.DateField(widget=MonthYearWidget)
# Get widget here -> https://djangosnippets.org/snippets/1688/
#admin.py
class SomeClassAdmin(admin.ModelAdmin):
list_display = ('format_date',)
def format_date(self, obj):
return obj.date.strftime('%b, %Y')
format_date.admin_order_field = 'date'
format_date.short_description = 'Date'
admin.site.register(SomeClass, SomeClassAdmin)
@TrungKien1230
Copy link

Hello, could you please add a full example ?

@Nokolay0710
Copy link

Hello!
It`s very good! Thenks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment