title: Annotate queryset with whether matching related object exists
body: <p>I have two models with an explicit many-to-many relationship: a thing, auth.user, and a "favorite" model connecting the two. I want to be able to order my "thing"s by whether or not they are favorited by a particular user. In Sqlite3, the best query i've come up with is (roughly) this:</p>
  
  <pre><code>select 
      *, max(u.name = "john cleese") as favorited 
      from thing as t 
          join favorite as f on f.thing_id = t.id 
          join user as u on f.user_id = u.id
      group by t.id
      order by favorited desc
      ;
  </code></pre>
  
  <p>The thing tripping me up in my sql-to-django translation is the <code>max(u.name = "john cleese")</code> bit. As far as I can tell, Django has support for arithmatic but not equality. The closest I can come is a case statement that doesn't properly group the output rows:</p>
  
  <pre><code>Thing.objects.annotate(favorited=Case(
      When(favorites__user=john_cleese, then=Value(True)),
      default=Value(False),
      output_field=BooleanField()
  ))
  </code></pre>
  
  <p>The other direction I've tried is to use <code>RawSQL</code>:</p>
  
  <pre><code>Thing.objects.annotate(favorited=RawSQL('"auth_user"."username" = "%s"', ["john cleese"]))
  </code></pre>
  
  <p>However, this won't work, because (as far as I'm aware) there's no way to explicitly join the <code>favorite</code> and <code>auth_user</code> tables I need.</p>
  
  <p>Is there something I'm missing?</p>