Django - Can you use property as the field in an aggregation function?

Posted by orokusaki on Stack Overflow See other posts from Stack Overflow or by orokusaki
Published on 2010-06-18T00:27:28Z Indexed on 2010/06/18 0:33 UTC
Read the original article Hit count: 251

I know the short answer because I tried it. Is there any way to accomplish this though (even if only on account of a hack)?

class Ticket(models.Model):
    account = modelfields.AccountField()
    uuid = models.CharField(max_length=36, unique=True)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created']

    @property
    def repair_cost(self):
        # cost is a @property of LineItem(models.Model)
        return self.lineitem_set.aggregate(models.Sum('cost'))

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models