title: Why doesn't this Django filter by 'annotate' variable work?
body: <p>I have this queryset in Django:</p>
  
  <pre><code>obj = Obj.objects.annotate(duration = F('date_end') - F('date_start')).order_by('duration')
  </code></pre>
  
  <p>The following works perfectly:</p>
  
  <pre><code>obj[0].duration
  
  obj.aggregate(Sum('duration'))['duration__sum']
  </code></pre>
  
  <p>However filtering doesn't work in this case even though documentation says that it should:</p>
  
  <pre><code>obj = obj.filter( duration__gte = &lt;a_class_datetime.timedelta&gt; )  # doesn't work
  obj = obj.filter( duration = 1 )   # doesn't work
  </code></pre>
  
  <p>This is the error I am getting:</p>
  
  <blockquote>
    <p>TypeError: expected string or bytes-like object</p>
  </blockquote>
  
  <p>My way to bypass this issue is to loop through the dataset - which is huge. Any tips as to why this is not working?</p>