【发布时间】:2014-04-11 11:14:12
【问题描述】:
我正在编写一个 django 项目并试图找出每个员工的总佣金。
我的销售模式:
class Sale(models.Model):
commission=models.DecimalField(max_digits=7,decimal_places=2,blank=True,null=True)
ouremployee=models.ForeignKey(Employee,blank=True,null=True)
我的销售对象已经记录了与每个销售和每个员工相关的佣金,但现在我想找到每个员工的总佣金。
我的员工模型:
class Employee(models.Model):
Name=models.CharField(max_length=30,blank=True,null=True)
Hire_date=models.DateTimeField(blank=True,null=True)
Salary=models.DecimalField(max_digits=8,decimal_places=1,blank=True,null=True)
Commission_rate=models.DecimalField(default=0,max_digits=3,decimal_places=3,blank=True,null=True)
Title=models.CharField(max_length=30,blank=True,null=True)
我的意见.py:
Sale = Sale.objects.all()
total_commission=0
TotalCommission = Sale.annotate(total_commission=Sum('ouremployee'))
我的views.py 不起作用。谁能帮帮我。
【问题讨论】:
-
已解决的问题仍应保留为问题,而不是编辑 - 这样其他人就可以找到它并利用所传授的知识。
-
...如果您认为某个问题的通用性不足以对其他人有用,那么它也不应该出现在 StackOverflow 上,并且应该被关闭和删除。
标签: python database django sum aggregation