Django - admin后台添加时间范围筛选 - django-daterange-filter

  实际效果:

 

1. 安装 

pip install django-daterange-filter

 

 2. settings.py 配置

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'daterange_filter',  # 配置
]

 

3. 使用


from django.contrib import admin
form apps.test.models import Order
from daterange_filter.filter import DateRangeFilter

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    list_display = ["id", "order_number", "create_time"]
    list_filter = [("create_time", DateRangeFilter)]

 

posted @ 2021-04-30 17:46  _Q  阅读(1267)  评论(0编辑  收藏  举报