XYZ.objects.extra(select={'z': 'x/y'}).annotate().order_by('-z')[0]
XYZ.objects.filter(x=models.F('y') * XYZ.objects.extra(select={'z':
    'MAX(x/y)'})[0].z)[0]
Django aggregate queries with expressions