From ef6a67ca2d9a3c41c9e8666d6d2c2edab777af63 Mon Sep 17 00:00:00 2001 From: Michael Elsdoerfer Date: Sat, 9 Jan 2010 00:11:17 +0100 Subject: [PATCH] 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. --- django_tables/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 -- 2.26.2