【发布时间】:2020-04-04 21:08:01
【问题描述】:
我正在关注 Mozilla 的 Django 教程,目前在 this 页面上。
我试图让Book 模型的ModelAdmin 调用ModelAdmin 的list_display 中的Book 模型的函数。这是为了在列表显示中提供流派列表。
我在admin.py 文件中有以下代码:
class BookAdmin(admin.ModelAdmin):
list_display('title', 'author', 'display_genre')
在models.py 文件中:
class Book(models.Model):
# ...
def display_genre(self):
return ', '.join(genre.name for genre in self.genre.all()[:3])
display_genre.short_description = 'Genre'
我相信这正是教程要求我添加到每个文件中的内容。
这是 django 在我尝试拨打 python manage.py makemigrations 时告诉我的:
SystemCheckError: System check identified some issues:
ERRORS:
<class 'catalog.admin.BookAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'display_genre', which is not a callable, an attribute of 'BookAdmin', or an attribute or method on 'catalog.Book'.
我不确定我做错了什么。
【问题讨论】:
标签: python django ubuntu mozilla