我希望 bool(boolean) 值字段在Django管理员的列表显示中可编辑。相反,我有不可编辑的图标:
我的代码如下所示:
# Model
class Task(models.Model):
...
is_finished = models.BooleanField()
# Admin
list_display = (..., 'is_finished')
我没有在
is_finished
的readonly_fields
元组中包含admin.py
,因此令我惊讶的是默认情况下它不可编辑。我究竟做错了什么? 最佳答案
ModelAdmin.list_editable
是您所需要的,请参阅其文档here。您在下面还有一个示例:
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"
关于django - 使 bool 值在list_display中可编辑?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18107589/