title: Django startswith on fields
body: <p>let's say that I have an Address model with a postcode field. I can lookup addresses with postcode starting with &quot;123&quot; with this line:</p>
  <pre><code>Address.objects.filter(postcode__startswith=&quot;123&quot;)
  </code></pre>
  <p>Now, I need to do this search the &quot;other way around&quot;. I have an Address model with a postcode_prefix field, and I need to retrieve all the addresses for which postcode_prefix is a prefix of a given code, like &quot;12345&quot;. So if in my db I had 2 addresses with postcode_prefix = &quot;123&quot; and &quot;234&quot;, only the first one would be returned.</p>
  <p>Something like:</p>
  <pre><code>Address.objects.filter(&quot;12345&quot;.startswith(postcode_prefix)) 
  </code></pre>
  <p>The problem is that this doesn't work.
  The only solution I can come up with is to perform a filter on the first char, like:</p>
  <pre><code>Address.objects.filter(postcode_prefix__startswith=&quot;12345&quot;[0])
  </code></pre>
  <p>and then, when I get the results, make a list comprehension that filters them properly, like this:</p>
  <pre><code>results = [r for r in results if &quot;12345&quot;.startswith(r.postcode_prefix)]
  </code></pre>
  <p>Is there a better way to do it in django?</p>