【发布时间】:2016-12-19 05:28:25
【问题描述】:
如何在我的模型中添加功能?
from django.db.models.functions import TruncMonth
ImportError: No module named functions
report.objects.filter(r_id=id, r_checkin_date__gte=checkin_date)
.annotate(month=ExtractMonth('timestamp'))
.values('month')
.annotate(count=Count('id'))
.values('month', 'count')
【问题讨论】:
-
您确定您使用的是支持此导入的正确 Django 版本吗?
-
在早于 1.10 的版本中不可用
-
是的。进口是支持的。我导入了很多库,但是当我要从问题来的函数中访问某些东西时。
-
我需要按月分组。有没有办法换一种方式?
标签: python django django-models django-views django-admin