Friday, January 4, 2019

Re: Filter by sum of filtered related objects?

Yes it is possible 

Lent Asia technologies pvt Ltd,

Aakash chaudhary

On Thu, 3 Jan 2019, 11:32 Dustin Wyatt <dustin.wyatt@gmail.com wrote:
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.

--
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/CAOB_BqpnZ7LpC1Dh4yGHD9isCLftv5dGLti5UsgMvffJjW8%2BFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment