python - Python 和 Django ,误差函数,问题出在哪里
问题描述
我有以下课程:
class Income(models.Model):
income = models.DecimalField()
date = models.DateField()
在我看来,我创建了一个算法,可以让我每月收集所有日期,如下所示:
now = datetime.datetime.now()
now = now.year
income = dict()
for year, month, totals in (Income.objects.values_list('date__year', 'date__month').annotate(totals = ExpressionWrapper(Sum(F('income')),
output_field = FloatField())).values_list('date__year', 'date__month', 'totals')):
if id not in income.keys() and year == now:
income[id] = list(defaults)
index = month - 1
income[id][index] = totals
如果我现在按以下方式设置,它会完美运行:
now=datetime.datetime.now()
now=now.year
但是,如果我以下列方式设置表单:
#
models
class Timing(models.Model):
reference_year = models.DateField()
# views
nows = []
form = TimingForm(request.POST or None)
if request.method == 'POST':
if form.is_valid():
nows = form.cleaned_data['reference_year']
nows = nows.year
Python给了我以下错误:
<built-in function id>
income[id][index]=totlas
为什么??
解决方案
推荐阅读
- javascript - 在 click 事件中将 javascript 对象分成具有 4 个项目的组
- python - Fortran 子例程不返回 python
- git - 从源分支移动提交,但在目标分支将被合并回来时保留它们?
- json - 计算一个特定的 json/word 出现了多少次
- ionic-framework - Ionic 2 去除离子清新剂下的线
- c# - 如何从 CosmosDB 中的特定类型获取所有项目
- c# - MVC如何将GUID转换为模型中的字符串
- javascript - 如何运行本地保存的 npm 包而不在 package.json 上设置它们?
- firebase - 如何使用 Firebase 云功能更新文档值
- html - css:如何在具有特定 2 列布局的另一个元素下浮动元素