Doubt about django model API

Posted by Clash on Stack Overflow See other posts from Stack Overflow or by Clash
Published on 2010-05-30T13:35:33Z Indexed on 2010/05/30 13:42 UTC
Read the original article Hit count: 316

Filed under:
|

Hello guys! So, here is what I want to do. I have a model Staff, that has a foreign key to the User model. I also have a model Match that has a foreign key to the User model.

I want to select how much Matches every Staff has. I don't know how to do that, so far I only got it working for the User model. From Staff, it will not allow to annonate Match.

This is what is working right now

User.objects.annotate(ammount=Count("match")).filter(Q(ammount__gt=0)).order_by("ammount")

And this is what I wanted to do

Staff.objects.annotate(ammount=Count("match")).filter(Q(ammount__gt=0)).order_by("ammount")

And by the way, is there any way to filter the matches? I want to filter the matches by a certain column.

Thanks a lot in advance!

© Stack Overflow or respective owner

Related posts about django

Related posts about django-models