0
我有如下一個Django模型:Django的GROUP BY查詢
class Recovery(models.Model):
Branch_Code = models.IntegerField('Branch Code',max_length=5, default=None)
RedDate = models.DateField('RecDate')
PrincipalRec = models.DecimalField('Principal Recovery',max_digits=18,decimal_places=2,default=None)
IntRec = models.DecimalField('Interest Recovery',max_digits=18,decimal_places=2,default=None)
ARC_Cash = models.DecimalField('ARC Cash Recovery',max_digits=18,decimal_places=2,default=None)
ARC_SR = models.DecimalField('ARC SR Recovery',max_digits=18,decimal_places=2,default=None)
Total_Rec = models.DecimalField('Total Recovery',max_digits=18,decimal_places=2,default=None)
def __unicode__(self):
return self.CIF
def Total_Rec_lacs(self):
return round(self.Total_Rec/100000 ,4)
def PrincipalRec_lacs(self):
return round(self.PrincipalRec/100000 ,4)
def IntRec_lacs(self):
return round(self.IntRec/100000 ,4)
def ARC_Cash_lacs(self):
return round(self.ARC_Cash/100000 ,4)
def ARC_SR_lacs(self):
return round(self.ARC_SR/100000 ,4)
此查詢通過 「Branch_Code」
top5 = Recovery.objects.filter(RedDate__gte = fromdate,RedDate__lte = todate,Total_Rec__gt=0).exclude(AssetType='AUCA').values('Branch_Code')\
.annotate(PrincipalRec=Sum('PrincipalRec'),IntRec=Sum('IntRec'),ARC_Cash=Sum('ARC_Cash'),Total_Rec=Sum('Total_Rec')).order_by('-Total_Rec')[:5]
這裏沒有fromdate和TODATE都具有有效的變量確實組日期值。上面的top5查詢工作正常,但是我想要將金額除以100 000,這樣金額將以lacs返回(上面的查詢返回整個金額)。
我曾嘗試下面的代碼,但沒有運氣:
top5npa = Recovery.objects.filter(RedDate__gte = fromdate,RedDate__lte = todate,Total_Rec__gt=0).exclude(AssetType='AUCA').values('Branch_Code')\
.annotate(PrincipalRec=Sum('PrincipalRec')/100000,IntRec=Sum('IntRec')/100000,ARC_Cash=Sum('ARC_Cash')/100000,Total_Rec=Sum('Total_Rec')/100000).order_by('-Total_Rec')[:5]