views:

49

answers:

1

Hi,

I keep numeric fields like "size", "width", "height" in my database. Now I would attach units like "KiB" or "pixels" to them when showing them in the change list. This could easily be achieved by adding callables such as "size_formatted" etc to list_display. However, these are no longer sortable.

Is there a way around this limitation?

+1  A: 

Read here - ModelAdmin.list_display (read a lot to get to the point ;) )

you need to add admin_order_field attribute to your function

class YourAdminCLass(admin.ModelAdmin)
   [...]
   def size_formatted(self, obj):
          return "whatever you need"
   size_formatted.admin_order_field = 'size'
Pydev UA
Hooray, a christmas present! Thanks for this.
Sam