Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #595 -- Fixed error when sorting API results descending with cu…

…stom 'select' parameters. Thanks for the patch, Robert Wittams

git-svn-id: http://code.djangoproject.com/svn/django/trunk@792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 485042b74d1ee3abb2f2ab4b4d814f2b9bcdad2c 1 parent 9fe02e6
Adrian Holovaty authored October 06, 2005

Showing 1 changed file with 8 additions and 5 deletions. Show diff stats Hide diff stats

  1. 13  django/core/meta/__init__.py
13  django/core/meta/__init__.py
@@ -1332,16 +1332,19 @@ def function_get_sql_clause(opts, **kwargs):
1332 1332
         if f == '?': # Special case.
1333 1333
             order_by.append(db.get_random_function_sql())
1334 1334
         else:
  1335
+            if f.startswith('-'):
  1336
+                col_name = f[1:]
  1337
+                order = "DESC"
  1338
+            else:
  1339
+                col_name = f
  1340
+                order = "ASC"
1335 1341
             # Use the database table as a column prefix if it wasn't given,
1336 1342
             # and if the requested column isn't a custom SELECT.
1337  
-            if "." not in f and f not in [k[0] for k in kwargs.get('select', [])]:
  1343
+            if "." not in col_name and col_name not in [k[0] for k in kwargs.get('select', [])]:
1338 1344
                 table_prefix = opts.db_table + '.'
1339 1345
             else:
1340 1346
                 table_prefix = ''
1341  
-            if f.startswith('-'):
1342  
-                order_by.append('%s%s DESC' % (table_prefix, orderfield2column(f[1:], opts)))
1343  
-            else:
1344  
-                order_by.append('%s%s ASC' % (table_prefix, orderfield2column(f, opts)))
  1347
+            order_by.append('%s%s %s' % (table_prefix, orderfield2column(col_name, opts), order))
1345 1348
     order_by = ", ".join(order_by)
1346 1349
 
1347 1350
     # LIMIT and OFFSET clauses

0 notes on commit 485042b

Please sign in to comment.
Something went wrong with that request. Please try again.