Django raw() query, calculated field in WHERE clause
问题 I'm wondering if there are any limitations on syntax of raw() method when using calculated fields. Here is a quick example: Company.objects.raw('''SELECT *,core_location.a + core_location.b as dist FROM core_location,core_company ORDER BY dist''') The above code works as expected (the results are sorted by calculated field 'dist'), but when I add WHERE clause, for example: Company.objects.raw('''SELECT *,core_location.a + core_location.b as dist FROM core_location,core_company WHERE dist<10