django admin totals,将总数添加到django admin中的列中。
admin-totals的Python项目详细描述
django管理总计
在Django管理列表中显示总计的模块。
安装
virtualenv .
source bin/activate
pip install admin-totals
或
pip install git+https://github.com/douwevandermeij/admin-totals.git
用法
在settings.py中
INSTALLED_APPS=['admin_totals',]
在admin.py中:
fromadmin_totals.adminimportModelAdminTotalsfromdjango.contribimportadminfromdjango.db.modelsimportSum,Avgfromdjango.db.models.functionsimportCoalesce@admin.register(MyModel)classMyModelAdmin(ModelAdminTotals):list_display=['col_a','col_b','col_c']list_totals=[('col_b',lambdafield:Coalesce(Sum(field),0)),('col_c',Avg)]
确保在list_display
中至少有list_totals
列。
测试
python runtests.py
贡献
在按下并制作PR之前,请确保运行以下命令:
pip install -r requirements/test-ci.txt
isort --recursive admin_totals tests
flake8
isort
将对导入进行排序,flake8
将对代码进行lint操作。请在提交之前修复任何错误。另外,请确保编写通过的测试。