如何禁用管理站点中多对多字段的数据

时间:2018-05-30 09:03:48

标签: python django

model.py

class Employee(models.Model):
    employeeid=models.IntegerField(primary_key=True, editable=True)
    fullname=models.CharField(max_length=500)
    location=models.ForeignKey(Location, on_delete=models.CASCADE)
    phone=models.IntegerField('phone number')
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
    )

    def __unicode__(self):
        return self.fullname

    def __str__(self):
        return self.fullname

admin.py

class holidayAdmin(FilterUserAdmin):
    form = select2_modelform(holiday,attrs={'width': '250px'})
    fields= ('type','start_date','end_date','employees','image_ref','note',)
    list_display = ('type','created_by','last_modified_by','start_date',
    'end_date','note','employees')

错误 错误: :(admin.E109)'list_display [6]'的值不能是ManyToManyField。

1 个答案:

答案 0 :(得分:1)

您无法在admin中的list_display中使用ManyToMany字段。 只需将list_display更改为

即可
list_display = ('type','created_by','last_modified_by','start_date',
                'end_date','note')