【发布时间】:2020-06-15 09:08:52
【问题描述】:
我认为以下代码:
def stato_patrimoniale(request):
now=datetime.datetime.now()
now=now.year
...
if Ricavi.objects.count()>0:
for year, month, totale in(Ricavi.objects.values_list( 'data_pagamento_acconto__year', 'data_pagamento_acconto__month').
annotate(totale=ExpressionWrapper(Sum(F('acconto')),
output_field=FloatField())).values_list('data_pagamento_acconto__year', 'data_pagamento_acconto__month', 'totale')):
if id not in incassi.keys() and year == now:
incassi[id]=list(defaults)
index=month-1
incassi[id][index]=totale
now变量用于过滤我在查询集中的数据,其中我的ricavi是以下模型:
class Ricavi(models.Model):
codice_commessa=models.ForeignKey(Informazioni_Generali, on_delete=models.CASCADE, null=True, blank=True)
# numero_lavorazione
acconto=models.DecimalField()
data_pagamento_acconto=models.DateField()
现在我想用一个表格替换now 变量,让我可以选择年份并更新我的观点。
我已经使用以下模型创建了另一个应用程序,该应用程序带有一个可以添加新年的表单:
class Timing(models.Model):
reference_year = models.DecimalField(max_digits=4, decimal_places=0, default="2020")
现在我想创建一个下拉按钮,其中包含所有填充的reference_year,当客户端单击其中一个时,我的def stato_patrimoniale(request): 中的now 变量会更新。我怎样才能达到这个目标?
【问题讨论】:
-
为什么不发布
year变量以在stato_patrimoniale中使用它? -
在什么意义上?
-
您想更新
now变量并更新您的视图。因此,当它发生变化时将其发布到stato_patrimoniale,然后更新now和... -
在您的请求中查找年份:request.POST['year']
标签: django django-models django-forms django-views django-templates