Gonzalo Dambra
Gonzalo Dambra

Reputation: 980

Django: Getting column max value as Integer

I have this:

maxAux = Auxi.objects.all().aggregate(Max('nroAux'))

Then I need to add +1 to its value, but doing:

maxAux = maxAux+1

will throw an error since aggregate(max returns a string value like {'nroAux__max': 5} and I only need this number 5.

Please avoid asnwering about id or django default autoincr column. I really need to make additions to my column nroAux. Thanks!!

Upvotes: 0

Views: 310

Answers (1)

ruddra
ruddra

Reputation: 52008

Aggregation actually returns a dictionary, and you can get the value same way as getting a value from dictionary using a key. For example (by using dict.get()):

maxAux = Auxi.objects.all().aggregate(max_val = Max('nroAux'))  # providing a key max_val

maxAux.get('max_val')

Upvotes: 4

Related Questions