Django管理员无法订购功能栏

时间:2011-04-23 14:54:47

标签: django django-admin

我有下面的代码,我已将描述更改为html safe。问题是订单不再有效,我无法将订单更改为'safe_description'。

class QuestionAdmin(admin.ModelAdmin):
    list_display = ('safe_description',)
    search_fields = ('description',)
    ordering = ('description',)

    def safe_description(self, obj):
        return mark_safe(obj.description)
    safe_description.short_description = 'Description'

1 个答案:

答案 0 :(得分:2)

Django并不神奇地知道safe_description已映射到您的description列。

使用admin_order_field属性

指定db列
safe_description.admin_order_field = 'description'