title: Queryset: Compare a field with a substring of another field of the same model
body: <p>I am trying to check if the first 3 characters of a Charfield (charfield_1) are similar to another Charfield (charfield_2) of the same model.</p>
  
  <p>Tried:</p>
  
  <pre><code>User.objects.filter(charfield_2__startswith=Substr('charfield_1', 1, 3))
  </code></pre>
  
  <p>Tried using F and Func without any success.
  I keep getting:</p>
  
  <pre><code>django.db.utils.DataError: invalid input syntax for integer: "1%"
  LINE 1: ...CE(REPLACE((SUBSTRING("model_name"."charfield_2", '1%', 3)),...
  </code></pre>
  
  <p>Any idea how to make this work? I would like a solution using the ORM to avoid performance issues.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>After checking the query generated by the ORM and the error message, it looks like the second Substr parameter is replaced by a non integer when I am using startswith or contains lookup expression.</p>
  
  <p>ex: Substr('charfield_1', 1, 3) is replace by Substr('charfield_1', '%1%', 3)</p>
  
  <p>I am using version 2.0.2.</p>
  
  <p>A ticket has been opened and accepted :
  <a href="https://code.djangoproject.com/ticket/29155" rel="nofollow noreferrer">https://code.djangoproject.com/ticket/29155</a></p>