Ticket #3397: admin_list.diff

File admin_list.diff, 1.4 KB (added by kent37@…, 18 years ago)

Patch to allow descending sort of non-DB fields

  • django/contrib/admin/templatetags/admin_list.py

     
    7272    for i, field_name in enumerate(lookup_opts.admin.list_display):
    7373        try:
    7474            f = lookup_opts.get_field(field_name)
     75            admin_order_field = None
    7576        except models.FieldDoesNotExist:
    7677            # For non-field list_display values, check for the function
    7778            # attribute "short_description". If that doesn't exist, fall
     
    8687                    header = field_name.replace('_', ' ')
    8788
    8889            # It is a non-field, but perhaps one that is sortable
    89             if not getattr(getattr(cl.model, field_name), "admin_order_field", None):
     90            admin_order_field = getattr(getattr(cl.model, field_name), "admin_order_field", None)
     91            if not admin_order_field:
    9092                yield {"text": header}
    9193                continue
    9294
     
    101103
    102104        th_classes = []
    103105        new_order_type = 'asc'
    104         if field_name == cl.order_field:
     106        if field_name == cl.order_field or admin_order_field == cl.order_field:
    105107            th_classes.append('sorted %sending' % cl.order_type.lower())
    106108            new_order_type = {'asc': 'desc', 'desc': 'asc'}[cl.order_type.lower()]
    107109
Back to Top