如何在管理页面中显示模型的所有字段? [英] How to show all fields of model in admin page?
本文介绍了如何在管理页面中显示模型的所有字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在这张照片中,只有标题显示在这里,我使用了:
In this picture, only the title shows up on here, I used:
def __unicode__(self):
return self.title;
如何显示所有这些字段?
How do I show all these fields?
如何显示每个模型页面中的所有字段?
推荐答案
默认情况下,管理员布局仅显示对象的 unicode 函数返回的内容。要显示其他内容,您需要在 app_dir / admin.py
中创建一个自定义管理表单。
By default, the admin layout only shows what is returned from the object's unicode function. To display something else you need to create a custom admin form in app_dir/admin.py
.
您需要添加一个管理表单,并且设置 list_display
字段。
You need to add an admin form, and setting the list_display
field.
在您的特定示例( admin.py )中:
In your specific example (admin.py):
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'price')
admin.site.register(Book, BookAdmin)
这篇关于如何在管理页面中显示模型的所有字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文