[Django]-Add filter by year in Django admin

4👍

You can add date_hierarchy = 'created_at' to your admin class.

class TaggedArticle(admin.ModelAdmin):
    date_hierarchy = 'created_at'
    fields = ['category_fit', 'article', 'link', 'relevant_feedback', 'category', 'user', 'email', 'created_at']
    list_display = ['article_id', 'link', 'user', 'created_at']
    list_filter = ['user', 'email']
    model = Tagged

It also provides the ability to filter by month, day in a better way than implementing it by ourselves.

1👍

Use django-daterange-filter package for filter on year.

And refer django-list-filter documentation.

May this helps you

Leave a comment