title: Convert the value of a field in a django RawQueryset to a different django field type
body: <p>I have a rather complex query that's generating a Django <code>RawQuerySet</code>. This specific query returns some fields that aren't part of the model that the <code>RawQuerySet</code> is based on, so I'm using <code>.annotate(field_name=models.Value('field_name'))</code> to attach it as an attribute to individual records in the <code>RawQuerySet</code>. The most important custom field is actually a <code>uuid</code>, which I use to compose URLs using Django's <code>{% url %}</code> functionality.</p>
  
  <p>Here's the problem: I'm not using standard <code>uuid</code>s inside my app, I'm using <a href="https://github.com/adamcharnock/django-smalluuid" rel="nofollow noreferrer">SmallUUIDs</a> (compressed UUIDs.) These are stored in the database as native <code>uuidfield</code>s then converted to shorter strings in python. So I need to somehow convert the <code>uuid</code> returned as part of the <code>RawQuerySet</code> to a <code>SmallUUID</code> for use inside a template to generate a URL.</p>
  
  <p>My code looks somewhat like this:</p>
  
  <pre><code>query = "SELECT othertable.uuid_field as my_uuid FROM myapp_mymodel
           JOIN othertable o ON myapp_mymodel.x = othertable.x"
  
  MyModel.objects.annotate(
      my_uuid=models.Value('my_uuid'),
  ).raw(query)
  </code></pre>
  
  <p>Now there is a logical solution here, there's an optional kwarg for <code>models.Value</code> called <code>output_field</code>, making the code look like this:</p>
  
  <pre><code>MyModel.objects.annotate(
      my_uuid=models.Value('my_uuid', output_field=SmallUUIDField()),
  ).raw(query)
  </code></pre>
  
  <p>But it doesn't work! That kwarg is completely ignored and the type of the attribute is based on the type returned from the database and not what's in <code>output_field</code>. In my case, I'm getting a <code>uuid</code> output because Postgres is returning a UUID type, but if I were to change the query to <code>SELECT cast othertable.uuid_field as text) as my_uuid</code> I'd get the attribute in the format of a string. It appears that Django (at least version 1.11.12) doesn't actually care what is in that kwarg in this instance.</p>
  
  <p>So here's what I'm thinking are my potential solutions, in no particular order:</p>
  
  <ol>
  <li>Change the way the query is formatted somehow (either in Django or in the SQL)</li>
  <li>Change the resulting RawQuerySet in some way before it's passed to the view</li>
  <li>Change something inside the templates to convert the UUID to a smalluuid for use in the URL reverse process.</li>
  </ol>
  
  <p>What's my best next steps here?</p>