if not lookup or callable(lookup):\r
continue\r
try:\r
- # let django validate the lookup\r
+ # Let Django validate the lookup by asking it to build\r
+ # the final query; the way to do this has changed in \r
+ # Django 1.2, and we try to support both versions.\r
_temp = self.queryset.order_by(lookup)\r
- _temp.query.as_sql()\r
+ if hasattr(_temp, 'as_sql'):\r
+ _temp.query.as_sql()\r
+ else:\r
+ from django.db import DEFAULT_DB_ALIAS\r
+ _temp.query.get_compiler(DEFAULT_DB_ALIAS).as_sql()\r
break\r
except FieldError:\r
pass\r