(admin.E108)'list_display [1]'的值表示'label',它是不可调用的,'?'的属性或'org.Org'上的属性或方法

时间:2019-02-28 00:59:41

标签: django django-models

我得到了错误:(admin.E108)'list_display [1]'的值引用了'label',它不是可调用的,不是'OrgAdmin'的属性,也不是'org上的属性或方法。组织”。当我尝试删除字段标签时,我不明白为什么。 (sqlite3)

感觉django好像在某处引用了该字段(在重构之前,我在 str 函数中使用了该字段,我不知道该如何同步它。

from django.db import models


class Org(models.Model):
  class Meta:
    # https://docs.djangoproject.com/en/2.1/ref/models/options/#django.db.models.Options.db_table
    db_table = "tfp_backoffice_org"
    verbose_name = 'Organization'

    # https://docs.djangoproject.com/en/2.1/ref/models/options/#indexes
    indexes = [
      models.Index(fields=['name', 'name']),
    ]

  name = models.CharField(
    help_text="Optional (autogenerated).<br />"
              "Must be url-compliant (slug, using '-' dash separator, no space, special char, etc.)",
    max_length=100,
  )
  label = models.CharField(
    help_text="Label displayed in French language",
    max_length=100,
  )
  label_fr = models.CharField(
    help_text="Label displayed in French language",
    max_length=100,
    blank=True,
    default="",
  )
  label_en = models.CharField(
    help_text="Label displayed in English language",
    max_length=100,
    blank=True,
    default="",
  )

  def __str__(self):
    return self.label_fr

1 个答案:

答案 0 :(得分:0)

错误不是在模型中(如错误消息中所述),而是在admin.py文件中。

from django.contrib import admin

from org.models import Org


class OrgAdmin(admin.ModelAdmin):
  list_display = ('name', 'label')  # The error was there


admin.site.register(Org, OrgAdmin)

问题非常明显,我一直在寻找model.py而不是admin.py。我想我错过了明显的事情。希望这对以后的人有所帮助!