title: Django aggregate queries with expressions
body: <p>I have a model XYZ and I need to get the max value for fields a, b, and expression x/y for a given queryset.</p>
  
  <p>It works beautifully for fields. Something like:</p>
  
  <pre><code>&gt;&gt;&gt; XYZ.all().aggregate(Max('a'))
  
  ... {'a__max': 10}
  </code></pre>
  
  <p>However, I can't find a way to do it for expressions. Trying something like:</p>
  
  <pre><code>&gt;&gt;&gt; XYZ.all().aggregate(Max('x/y'))
  </code></pre>
  
  <p>Gives an error:</p>
  
  <pre><code>*** FieldError: Cannot resolve keyword 'x/y' into field. Choices are: a, b, x, y, id
  </code></pre>
  
  <p>Trying something like:</p>
  
  <pre><code>&gt;&gt;&gt; XYZ.all().aggregate(Max(F('x')/F('y')))
  </code></pre>
  
  <p>Gives an error:</p>
  
  <pre><code>*** AttributeError: 'ExpressionNode' object has no attribute 'split'
  </code></pre>
  
  <p>And even something like:</p>
  
  <pre><code>XYZ.all().extra(select={'z':'x/y'}).aggregate(Max('z'))
  </code></pre>
  
  <p>Also doesn't work and gives the same error as above:</p>
  
  <pre><code>FieldError: Cannot resolve keyword 'z' into field. Choices are: a, b, x, y, id
  </code></pre>
  
  <p>The one hack I found to do it is:</p>
  
  <pre><code>XYZ.all().extra(select={'z':'MAX(x/y)'})[0].z
  </code></pre>
  
  <p>Which actually works because it generates the right SQL, but it's confusing because I do get the right value at the z atttribute, but not the right instance, the one with that max value.</p>
  
  <p>Of course, I could also use raw queries or tricks with extra() and order_by(), but it really doesn't make sense to me that Django goes all the way to support aggregate queries in a nice way, but can't support expressions even with its own F expressions.</p>
  
  <p>Is there any way to do it?</p>