[Django]-Django "through" model iteration

6👍

Yes.

Person.organization_set.all() should return the list of organisations to which the Person in question belongs. For each organisation in that set, you can then return their position, so:

p = Person.objects.get(id=personid)

for o in p.organization_set.all():
    # you have o and p, you should be able to find a unique m.
    m = Membership.objects.get(Person=p, Organization=o)

See the documentation here.

Leave a comment