How can I access the "through" object of a Django ManyToManyField?

Posted by Macha on Stack Overflow See other posts from Stack Overflow or by Macha
Published on 2010-03-20T17:13:15Z Indexed on 2010/03/20 17:21 UTC
Read the original article Hit count: 167

Filed under:
|

I have the following models in my Django app. How can I from the Team model find all the User objects who have accepted as True in the Membership model? I know I need to use Team.objects.filter(), but I'm not sure how to check the value of the accepted field.

from django.contrib.auth.models import User
class Team(models.Model):
    members = models.ManyToManyField(User, through="Membership")

class Membership(models.Model):
    user = models.ForeignKey(User)
    team = models.ForeignKey(Team)
    accepted = models.BooleanField(default=False)

© Stack Overflow or respective owner

Related posts about django

Related posts about python