I intend to make a query to get a value and then add that value to 1 in the django views, but when I try to do that, I always get an error
def atualizar(request, contador):
lista = factura.objects.filter(contador__contador=contador)
conta1 = factura.objects.filter(contador__contador=contador).order_by('-contar')[:1]
conta=conta1.values('contar') # this is value
cont=cliente.objects.filter(contador=contador).first()
if request.POST:
data1=request.POST['data1']
factura_nr=request.POST['factura_nr']
data2=request.POST['data2']
consumo=request.POST['consumo']
dados = factura(
contador=cont,
contar= conta +1, # to incremet here
consumo=consumo,
data1=data1,
data2=data2,
factura_nr=factura_nr
)
dados.save()
return render(request, 'tabela.html', {'lista': lista,'cont':cont ,'conta':conta})[enter image description here](https://i.stack.imgur.com/BdaMk.png)
2
Answers
updated:
values() returns a Queryset that behaves similar to a dict. Simply try
to debug
print(conta)
and you will see itplease add the error trace in future posts
You can determine the maximum
contar
and then increment this with one, like: