0

First of all, I'm using Django 2.2 and Python 3.7

I have this in my models.py

class Test(models.Model):
    session = models.IntegerField()
    x_pos = models.IntegerField()
    y_pos = models.IntegerField()

What am trying to do is to get the max value of 'session' from my database.

In my views.py I succesfully get the max value by this:

from .models import Test
from django.db.models import Max

max_session = Test.objects.all().aggregate(Max('session'))
print(max_session)

The problem is when I print the result i get {'session__max': 35}

How can I get the value 35 only, in my max_session variable?

hotperis
  • 3
  • 1
  • try print(max_session['session_max']) – cicero Jun 06 '19 at 08:40
  • @julien unfortunately that gives me an error: print(max_session['session_max']) **KeyError: 'session_max'** – hotperis Jun 06 '19 at 08:49
  • could you provide exactly the output of `print(max_session)` ? From what you provided the output is a dictionnary with 'session_max' key, so you should not have a KeyError – cicero Jun 06 '19 at 08:57
  • Ah I forgot an underscore, try `print(max_session['session__max'])` – cicero Jun 06 '19 at 08:58

1 Answers1

1
print(max_session['session__max'])
cicero
  • 508
  • 3
  • 15