Reputation: 326
I am currently having the following
class Profile(models.Model):
gender = models.BooleanField()
class Q(models.Model):
name = models.CharField(max_length=128)
class A(models.Model):
q = models.ForeignKey(Q)
profile = models.ForeignKey(Profile)
What I try to do is to query Q and get the number of Answers given by either male or female?
Unfortunately, I don't even have a better idea than writing custom SQL, which I'd rather avoid for the sake of database portability. How would I start?
Upvotes: 0
Views: 111
Reputation: 239290
You're there. You just need to actually use the right filter syntax. If you're trying filter on the gender
field on profile
, then you do that with profile__gender
, so:
males_answering = question.answers.filter(profile__gender="male").count()
Upvotes: 1