Ticket #595: django-custom-select-desc-fix.patch

File django-custom-select-desc-fix.patch, 1.4 KB (added by anonymous, 9 years ago)
  • __init__.py

     
    13321463        if f == '?': # Special case.
    13331464            order_by.append(db.get_random_function_sql())
    13341465        else:
     1466            if f.startswith('-'):
     1467                col_name = f[1:]
     1468                order = "DESC"
     1469            else:
     1470                col_name = f
     1471                order = "ASC"
    13351472            # Use the database table as a column prefix if it wasn't given,
    13361473            # 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', [])]:
     1474            if "." not in col_name and col_name not in [k[0] for k in kwargs.get('select', [])]:
    13381475                table_prefix = opts.db_table + '.'
    13391476            else:
    13401477                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)))
     1478           
     1479            order_by.append('%s%s %s' % (table_prefix, orderfield2column(col_name, opts), order))
     1480   
    13451481    order_by = ", ".join(order_by)
    13461482
    13471483    # LIMIT and OFFSET clauses
Back to Top