Django Manytomany filter with intermediate model
<p>I have the following models:</p>

<pre><code>class Personne(BaseModel):
    user = models.OneToOneField(User)
    relations = models.ManyToManyField('self', through='PersonneRelation',
                                       symmetrical=False,
                                       related_name='personne_relations')

class PersonneRelation(BaseModel):
    type_relation = models.IntegerField(
        choices=[(a, b) for a, b in list(PersonneEnums.TAB_RELATIONS.items())],
        default=PersonneEnums.RELATION_FRIEND)
    src = models.ForeignKey('Personne', related_name='relation_src')
    dst = models.ForeignKey('Personne', related_name='relation_dst')
</code></pre>

<p>In my view, I have the currently logged user via </p>

<pre><code>p_user = Personne.objects.get(user=view.request.user)
</code></pre>

<p>I want to retrieve all the relation of <code>p_user</code> that are of type <code>PersonneEnums.RELATION_FRIEND</code></p>

<p>I've tried many things including the following code, but nothing works:</p>

<p>Doesn't work :</p>

<pre><code>p_user.objects.filter(relations__type_relation__exact=PersonneEnums.RELATION_AMI)
</code></pre>

<p>Doesn't work:</p>

<pre><code>Personne.objects.filter(
    pk=p_user.pk,
    relations__type_relation__exact=PersonneEnums.RELATION_AMI
)
</code></pre>

<p>Can someone explain to me why this does not work?</p>