I have in my views the following code:
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
The now variable is used to filter my data in the queryset, where my ricavi is the following models:
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 I want to replace the now variable witha a form that give me the possibility to choose the year and update my views.
I have created another app with the following model that with a form gives the possibility to add new year:
class Timing(models.Model):
reference_year = models.DecimalField(max_digits=4, decimal_places=0, default="2020")
Now I want to create a dropdown button that contains all the reference_year filled and when the client click on one of them, the now variable in my def stato_patrimoniale(request): is updated. How could I get this aim?
yearvariable to use it instato_patrimoniale?nowvariable and update your view. So post it tostato_patrimonialewhen it changes then, updatenowand ...