本文介绍了使布尔值在list_display中可编辑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like a boolean field to be editable in my Django admin's list display. Instead, I have uneditable icons:

我的代码如下:

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

我尚未在 is_finished 中添加 admin.py 中的 readonly_fields 元组,因此我很惊讶默认情况下它不可编辑。我在做什么错了?

I haven't included is_finished in the readonly_fields tuple in admin.py, so I'm surprised that it isn't editable by default. What am I doing wrong?

推荐答案

ModelAdmin.list_editable 需要时,请在中查看其文档。下面还有一个示例:

ModelAdmin.list_editable is what you need, see its doc here. Below you also have an example:

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"

这篇关于使布尔值在list_display中可编辑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 09:54