Django filter with two hops over ForeignKeys
<p>In Django, is it possible to do something like this?</p>

<p><code>foo = Account.objects.filter(owner__address__zipcode='94704').get()</code></p>

<p>with the following premises:</p>

<ul>
<li>Account has an <code>Owner</code> foreign key to an Owner model.</li>
<li>Owner has an <code>Address</code> foreign key to an Address model.</li>
<li>Address has a <code>zipcode</code> char field.</li>
</ul>

<p>Yes, this is supported in Django ORM.  </p>

<p>The feature is <a href="https://docs.djangoproject.com/en/dev/topics/db/queries/#lookups-that-span-relationships" rel="nofollow">documented here</a>.  </p>

python django django-models