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'
精彩评论