2011-02-05 8 views

답변

1

우선의

감사합니다, 그것은 from django.db.models import Max 것입니다,하지만 당신은 1.1에 도입되었고, 어쨌든 ImportError를 던질 것 맞아요.

당신은 잠재적으로 extra()
http://docs.djangoproject.com/en/1.0/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none

Model.objects.extra(select={'max':'MAX(myfield)'})[0].max 

을 사용하거나 SQL에 갈 수 :
http://docs.djangoproject.com/en/dev/topics/db/sql/#executing-custom-sql-directly

from django.db import connection 

cursor = connection.cursor() 
cursor.execute("SELECT MAX(myfield) from myapp_mytable") 
max = cursor.fetchone()[0] 
+0

감사합니다. 그것은 오타였습니다. –

관련 문제