在我的模型中,我有金额字段,我想要总和金额。
遵循我的模型;的 model.py
class EntityLoan(models.Model):
id = models.BigIntegerField(primary_key=True)
amount = models.FloatField(blank=True, null=True)
status = models.ForeignKey('StaticStatus',db_column='status',related_name='+status+')
start_date = models.DateTimeField(blank=True, null=True)
end_date = models.DateTimeField(blank=True, null=True)
last_modified_by = models.ForeignKey('EntityUser', db_column='last_modified_by')
last_modified_date = models.DateTimeField()
class Meta:
db_table = 'entity_loan'
以下是我的tastypie资源代码 api.py
class LoanResource(ModelResource):
class Meta:
queryset = EntityLoan.objects.all()
resource_name = 'entityloan'
fields = ['amount']
filtering = {
'amount': ALL,
}
def determine_format(self, request):
return 'application/json'
def dehydrate(self,bundle):
items= bundle.obj.amount.all()
bundle.data['item_count']=items.Sum('amount')
bundle.data['items'] = [i.to_dict() for i in items]
return bundle
但我收到错误
error_message“:”'float'对象没有属性'all'“,