django (admin.E108)“list_display[1]”的值引用了“label”,而“label”不是可调用项、“?"属性或者”org.org“上的属性或方法

cvxl0en2  于 2023-01-18  发布在  Go
关注(0)|答案(2)|浏览(140)

我得到错误:(admin.E108)“list_display[1]”的值引用了“label”,而“label”不是可调用项、“OrgAdmin”的属性或者“org.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
uxhixvfz

uxhixvfz1#

错误不在模型中(如错误消息中所述),而是在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上查找。我想我错过了明显的问题。希望这对将来的人有帮助!

lskq00tm

lskq00tm2#

我遇到了这个错误,但原因不同。我在www.example.com文件中定义了一个字段models.py:
transaction_date = models.DateField(name="Date")
name=“Date”将更改字段标签。admin.py必须使用“Date”而不是“transaction_date”:

class AllTransactionsAdmin(admin.ModelAdmin):
    list_display = ("Date", etc)

相关问题