title: How do I select from a subquery using the Django ORM?
body: <p>I have a table that is meant to be insert only.  It has columns for <code>id</code>, <code>object_id</code>, and <code>user_id</code>.  When you update a record, instead of updating the row, you create a new record with a matching <code>object_id</code>.</p>
  <p>I'm trying to pull all records that match a given <code>user_id</code> with the highest <code>id</code> for each individual <code>object_id</code>.</p>
  <p>I can do what I'm attempting to describe with a subquery like so:</p>
  <pre><code>SELECT * FROM (SELECT * FROM table WHERE user_id = 100 ORDER BY object_id, id DESC) adr_table GROUP BY object_id
  </code></pre>
  <p>I've tried using the <code>raw()</code> method, but it returns a <code>RawQuerySet</code> object and I'm trying to feed it to a form that needs a <code>QuerySet</code>.</p>
  <p>I'd ideally like to get rid of the <code>raw()</code> and just use the Django ORM, but if that isn't possible, how can I convert the <code>RawQuerySet</code> to a regular <code>QuerySet</code>?</p>