Django

Code

Changeset 792

Show
Ignore:
Timestamp:
10/06/05 10:52:30 (3 years ago)
Author:
adrian
Message:

Fixed #595 -- Fixed error when sorting API results descending with custom 'select' parameters. Thanks for the patch, Robert Wittams

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/meta/__init__.py

    r698 r792  
    13331333            order_by.append(db.get_random_function_sql()) 
    13341334        else: 
     1335            if f.startswith('-'): 
     1336                col_name = f[1:] 
     1337                order = "DESC" 
     1338            else: 
     1339                col_name = f 
     1340                order = "ASC" 
    13351341            # Use the database table as a column prefix if it wasn't given, 
    13361342            # 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', [])]: 
    13381344                table_prefix = opts.db_table + '.' 
    13391345            else: 
    13401346                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)) 
    13451348    order_by = ", ".join(order_by) 
    13461349