在我看来,我得到了 points_total,但是它返回的所有点与 points_list 不同,它由当前用户过滤。
问题:
1) 我如何像在“points_list”中一样按用户过滤“def points_total”
模型.py
class PointsManager(models.Manager):
def points_list(self,thisUser):
list = Points.objects.filter(user=thisUser)
return list
def points_total(self,thisUser):
return Points.objects.aggregate(models.Sum('points'))
class Points (models.Model):
statusOptions = (
(0, 'Pending'),
(1, 'Added'),
(2, 'Deducted'),
(3, 'Processing'),
)
user = models.ForeignKey(User)
points = models.IntegerField(verbose_name=("Points"), default=0)
created = models.DateTimeField(("Created at"), auto_now_add=True)
updated = models.DateTimeField(verbose_name=("Updated at"), auto_now=True)
status = models.IntegerField(default=0, choices=statusOptions)
objects = PointsManager()
class Meta:
verbose_name = ('Point')
verbose_name_plural = ('Points')