From: Michael Elsdoerfer Date: Fri, 8 Jan 2010 23:11:17 +0000 (+0100) Subject: Fix for #503652 (thanks Zeth). The quasi-internal APIs to retrieve the SQL code for... X-Git-Tag: 0.2~29^2~2 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ef6a67ca2d9a3c41c9e8666d6d2c2edab777af63;p=django-tables2.git Fix for #503652 (thanks Zeth). The quasi-internal APIs to retrieve the SQL code for a queryset will change in 1.2. We now support both 1.2 and previous versions. --- diff --git a/django_tables/models.py b/django_tables/models.py index be0cf5f..cfd1d48 100644 --- a/django_tables/models.py +++ b/django_tables/models.py @@ -120,9 +120,15 @@ class BaseModelTable(BaseTable): if not lookup or callable(lookup): continue try: - # let django validate the lookup + # Let Django validate the lookup by asking it to build + # the final query; the way to do this has changed in + # Django 1.2, and we try to support both versions. _temp = self.queryset.order_by(lookup) - _temp.query.as_sql() + if hasattr(_temp, 'as_sql'): + _temp.query.as_sql() + else: + from django.db import DEFAULT_DB_ALIAS + _temp.query.get_compiler(DEFAULT_DB_ALIAS).as_sql() break except FieldError: pass