Django - filter model
<p>I have a model with a field that is a list.
For example:</p>

<pre><code>mymodel.sessions = [session1, session2]
</code></pre>

<p>I need a query to get all <code>mymodels</code> that <code>session1</code> is exist their sessions.</p>

<p>The model`s field looks like that</p>

<pre><code>sessions = models.ForeignKey("Session", related_name="abstracts",
                                null=True, blank=True)
</code></pre>

<p>Thank you !</p>

<p>You can use reverse lookups that go back along the foreign key to query for values in the related model.</p>

<pre><code>MyModel.objects.filter(sessions__id=1)
</code></pre>

<p>That will filter all <code>MyModel</code>s that have a foreign key to a session with an <code>id</code> of 1.</p>

<p>For more information see <a href="https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships" rel="nofollow">https://docs.djangoproject.com/en/1.10/topics/db/queries/#lookups-that-span-relationships</a></p>

python django django-models