Finding object count where a field is unique in Django

Posted by Johnd on Stack Overflow See other posts from Stack Overflow or by Johnd
Published on 2009-05-10T17:29:58Z Indexed on 2010/04/16 8:23 UTC
Read the original article Hit count: 160

Filed under:

I have a model that is something like this:

class Input(models.Model):
        details = models.CharField(max_length=1000)
        user = models.ForeignKey(User)

class Case(Input):
    title  = models.CharField(max_length=200)
    views = models.IntegerField()

    class Argument(Input):
        case = models.ForeignKey(Case)
        side = models.BooleanField()

A user can submit many arguments, per case. I want to be able to say how many users have submitted side=true arguments.

I mean if 1 user had 10 arguments and another user had 2 arguments (both side=true) I'd want the count to be 2, not 12.

© Stack Overflow or respective owner

Related posts about django