We can use callable functions when we define the ModelAdmin?.list_display property, but when we try to short then, an TypeError? exception is raised:
Exception Type: TypeError
Exception Value: getattr(): attribute name must be string
Exception Location: /home/rgl/Projects/django/django-trunk/django/contrib/admin/views/main.py in get_ordering, line 160
The attached patch fixes this.
This problem can be seen in the following ModelAdmin? example; it uses two callables "admin_lat" and "admin_lng":
from django.contrib import admin
from airports.models import Airport
# See "callable" at http://docs.djangoproject.com/en/dev/ref/contrib/admin/#list-display
def admin_lat(airport):
return '%.6f' % airport.lat
admin_lat.short_description = "Latitude"
admin_lat.admin_order_field = 'lat'
def admin_lng(airport):
return '%.6f' % airport.lng
admin_lng.short_description = "Longitude"
admin_lng.admin_order_field = 'lng'
class AirportAdmin(admin.ModelAdmin):
list_display = ('iata_code', 'name', admin_lat, admin_lng, 'tz', 'country')
list_filter = ('country', )
search_fields = ('=iata_code', )
admin.site.register(Airport, AirportAdmin)