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):
        return 
Transaction.objects.filter(created="""DATE_VALUE_HERE""").filter(product=self.id).count()

I tried to adjust the queryset in a class that extends SimpleListFilter, 
however I did not manage to make it work.

Another thing I thought of was to add an additional parameter to 
num_of_trans function, but it seems there is not way to pass this parameter 
while using the filter.

I would appreciate any tips.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/c1612d89-d28b-4c82-b17d-703c43cc581d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to