简单的情况,型号:
class Manufacturer(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, null=True)
active = models.BooleanField()
...
和ModelAdmin:
class ManufacturerAdmin(admin.ModelAdmin):
search_fields = ['name']
list_filter = ['assortment_type', 'active']
ordering = ('priority',)
prepopulated_fields = {'slug':('name',),}
list_display = ('name', 'active')
仍然在管理员活动列中显示为True / False而不是图标。我可以创建方法并设置Boolean = True属性但是我失去了对列的排序能力。很明显,我在这里遗漏了一些东西。
答案 0 :(得分:3)
创建自定义方法,然后将admin_order_field
设置为字段名称,将boolean
设置为True
def my_function(self):
# your stuff goes here
my_function.boolean = True
my_function.admin_order_field = 'active'
这应该使它可以排序(doc)