diff options
| author | Adrian Holovaty <adrian@holovaty.com> | 2005-10-06 15:52:30 +0000 |
|---|---|---|
| committer | Adrian Holovaty <adrian@holovaty.com> | 2005-10-06 15:52:30 +0000 |
| commit | 485042b74d1ee3abb2f2ab4b4d814f2b9bcdad2c (patch) | |
| tree | 3fa1dd8c4ff920f28b74490ba1836fc3d4814c4b | |
| parent | 9fe02e6b65bf6adb9f2bcb07e19e3bfbb5f918af (diff) | |
Fixed #595 -- Fixed error when sorting API results descending with custom 'select' parameters. Thanks for the patch, Robert Wittams
git-svn-id: http://code.djangoproject.com/svn/django/trunk@792 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/core/meta/__init__.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/django/core/meta/__init__.py b/django/core/meta/__init__.py index 3ca42f14e6..0c6078705a 100644 --- a/django/core/meta/__init__.py +++ b/django/core/meta/__init__.py @@ -1332,16 +1332,19 @@ def function_get_sql_clause(opts, **kwargs): if f == '?': # Special case. order_by.append(db.get_random_function_sql()) else: + if f.startswith('-'): + col_name = f[1:] + order = "DESC" + else: + col_name = f + order = "ASC" # Use the database table as a column prefix if it wasn't given, # and if the requested column isn't a custom SELECT. - if "." not in f and f not in [k[0] for k in kwargs.get('select', [])]: + if "." not in col_name and col_name not in [k[0] for k in kwargs.get('select', [])]: table_prefix = opts.db_table + '.' else: table_prefix = '' - if f.startswith('-'): - order_by.append('%s%s DESC' % (table_prefix, orderfield2column(f[1:], opts))) - else: - order_by.append('%s%s ASC' % (table_prefix, orderfield2column(f, opts))) + order_by.append('%s%s %s' % (table_prefix, orderfield2column(col_name, opts), order)) order_by = ", ".join(order_by) # LIMIT and OFFSET clauses |
