开发者

Django admin cannot order function column

开发者 https://www.devze.com 2023-02-28 12:27 出处:网络
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\'.

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

精彩评论

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