开发者

Django admin cannot order function column

I have the code below, I have change the description to html safe开发者_如何学编程. The problem is the ordering is not working anymore, I cannot change the ordering to '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'


Django doesn't magically know that safe_description is mapped to your description column.

Specify the db column with the admin_order_field attribute

safe_description.admin_order_field = 'description'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜