Thursday, January 3, 2019

Filter by sum of filtered related objects?

Given the following models:


class Transaction(models.Model):
  amount = models.IntegerField()
  date = models.DateField()
  terms = models.ForeignKey('Terms')


class Terms(models.Model):
  name = models.CharField(max_length=100)
  timezone = models.CharField(max_length=50)


I need to annotate Terms with the sum of the related Transaction.amount's where the Transaction.date is between two dates and what those two dates are varies by Terms.timezone.

Possible?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/02257cdb-55a5-4ae9-bc2d-3b3fef0ef91f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment