Instead of self.id you should use self itself as using self.id will not
work.


On Mon, Jul 7, 2014 at 4:17 PM, <[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):
>         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 [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/c1612d89-d28b-4c82-b17d-703c43cc581d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c1612d89-d28b-4c82-b17d-703c43cc581d%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [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/CAOdEGu3rA6vM2XJvci9Li-0p%2BVvF8h7WJ9gNvV%2BBfibCovyFXQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to