0
在Django視圖中,我運行以下代碼以獲得「位置」列的最大值,其中「groupMain_id」等於10 :Django查詢集過濾器和聚合最大值,然後把最大值放到一個變量中
lastposition = BlockMain.objects.filter(groupMain_id = 10).aggregate(themax=Max('position'))
testvar=lastposition
#Result
# {'themax': 3}
如何將值「3」賦值給變量「testvar」? 如果我使用的testvar = lastposition.themax收到錯誤:
Exception Type: AttributeError Exception Value: 'dict' object has no attribute 'themax'