On Mon, Jul 7, 2014 at 11:47 AM,  <[email protected]> wrote:
> There are tables Product and Transaction. In Product admin there is a field
> that shows how many transactions have been created with this product.
>
> Now, I want to filter the period of time in which these transactions were
> created. For example, there was 30 transactions in the last week, but 100 in
> the last month.
>
> class Transaction(models.Model):
>     created = models.DateTimeField()
>     product = models.ForeignKey('Product')
>
> class Product(models.Model):
>     name = models.CharField()
>
     def num_of_trans(self, start_date=None, end_date=None):
          qs = self.transaction_set.all()
          if start_date:
              qs = qs.filter(created__gt=start_date)
          if end_date:
              qs = qs.filter(created__lt=end_date)
          return qs


Does that suffice?

Cheers

Tom

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1K9o1ujaZbRjtuM3Tm9f%3DzkR5WAN5MHpWYaBYs-kF%2BWQQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to