29

我希望在我的 Django 管理员列表显示中可以编辑一个布尔字段。相反,我有不可编辑的图标:

在此处输入图像描述

我的代码如下所示:

# Model
class Task(models.Model):
  ...
  is_finished = models.BooleanField() 
# Admin
list_display = (..., 'is_finished')

我没有包含is_finishedreadonly_fields元组中admin.py,所以我很惊讶它在默认情况下是不可编辑的。我究竟做错了什么?

4

1 回答 1

54

ModelAdmin.list_editable是您需要的,请在此处查看其文档。下面还有一个例子:

class TaskAdmin(models.ModelAdmin):
    list_display = (..., 'is_finished')
    list_editable = ('is_finished',) # this MUST only contain fields that also are in "list_display"
    #list_display_links = ('foo', 'bar') # this MUST NOT contain a field in common with "list_editable"
于 2013-08-07T15:41:48.743 回答