当前位置: 代码迷 >> 综合 >> crm4-创建自己的admin时发生(admin.E108) The value of 'list_display[5]' refers to 'status',
  详细解决方案

crm4-创建自己的admin时发生(admin.E108) The value of 'list_display[5]' refers to 'status',

热度:66   发布时间:2024-01-24 15:05:51.0

 

 

我在admin.py中定义了一个CustomerAdmin类

class CustomerAdmin(admin.ModelAdmin):list_display = ('id', 'qq', 'source', 'consultant', 'content', 'status', 'date')list_filter = ('source', 'consultant', 'date')search_fields = ('qq', 'name')raw_id_fields = ('consult_course',)filter_horizontal = ('tags',)list_editable = ('status',)

 

 

 

一直报错

ERRORS:

<class 'crm.admin.CustomerAdmin'>: (admin.E108) The value of 'list_display[5]' refers to 'status', which is not a callable, an attribute of 'CustomerAdmin', or

<class 'crm.admin.CustomerAdmin'>: (admin.E121) The value of 'list_editable[0]' refers to 'status', which is not an attribute of 'crm.Customer'.

 

 

经过各种搜索排查发现因为在models.py中

 

class Customer(models.Model):"""客户信息表"""name = models.CharField(max_length=32,blank=True,null=True)qq = models.CharField(max_length=64,unique=True)qq_name = models.CharField(max_length=64,blank=True,null=True)phone = models.CharField(max_length=64,blank=True,null=True)source_choices = ((0, '转介绍'),(1, 'QQ群'),(2, '官网'),(3, '百度推广'),(4, '51CTO'),(5, '知乎'),(6, '市场推广'))source = models.SmallIntegerField(choices=source_choices)referral_from = models.CharField(verbose_name="转介绍人qq",max_length=64,blank=True)consult_course = models.ForeignKey("Course",verbose_name="咨询课程",on_delete=models.CASCADE)content = models.TextField(verbose_name="咨询详情")tags = models.ManyToManyField("Tag",blank=True,null=True)consultant = models.ForeignKey("UserProfile",on_delete=models.CASCADE)memo = models.TextField(blank=True,null=True)date = models.DateTimeField(auto_now_add=True)def __str__(self):return self.qq

 

Customer类中并没有定义status字段,所以报错

 

解决方案1:

将admin.py中CustomerAdmin类中有status的删掉就OK了,修改成如下就OK了

class CustomerAdmin(admin.ModelAdmin):list_display = ('id', 'qq', 'source', 'consultant', 'conten', 'date')list_filter = ('source', 'consultant', 'date')search_fields = ('qq', 'name')raw_id_fields = ('consult_course',)filter_horizontal = ('tags',)# list_editable = ('status',)

 

解决方案2:

在models.py的Customer类中定义status字段,也可以解决问题。

 

浏览了很多类似的错误,总结了一下,发现大家产生这种错误的原因大多这两种:

第一种就是我这种,未定义相应字段,有些定义了,但是粗心单词拼写错误,这种不容易发现

第二种就是缩进错误导致,空格和tab键混用

如果这两种都不是,那就再找找看其他原因吧~~~

 

 

 

  相关解决方案