如何在Django管理员中以表格格式显示添加模型? [英] How do I display add model in tabular format in the Django admin?
问题描述
我刚开始用Django编写我的第一个应用程序 - 一个为家人做家务的经理。在本教程中,它将向您展示如何添加相关对象表格形式。我不关心相关对象,我只是想以表格形式添加常规对象。这是我在我的admin.py中
从chores.models import Chore
from django.contrib import admin
class ChoreAdmin(admin.ModelAdmin):
fieldsets = [
(无,{'fields':['description','frequency','person']})
]
admin.site.register(Chore,ChoreAdmin)
我想要点击添加琐事,而不是看到:
说明:_____
频率: ______
个人:_____
我想要显示:
说明:__________ |频率:_______ |个人:_____
这样做很简单,还是需要很多自定义的努力?如果很容易,我该怎么做?
谢谢!
OP可能已经设置好了,但是对于阅读此操作的新用户,请参阅: https://docs.djangoproject.com/en/dev/ref/contrib/admin/
基本上遵循上述链接:
field_options
字典可以具有以下密钥:
fields
:要在此字段集中显示的字段名称的元组。这个键是必需的。
示例:
{
'fields':('first_name','last_name','address','city','state'),
}
就像使用字段
选项一样,在同一行显示多个字段,将这些字段包装在自己的元组中。在此示例中, first_name
和 last_name
字段将显示在同一行:
{
'fields':(('first_name','last_name'),'address','city','state'),
}
I'm just starting out with Django writing my first app - a chore chart manager for my family. In the tutorial it shows you how to add related objects in a tabular form. I don't care about the related objects, I just want to add the regular object in a tabular form. This is what I have in my admin.py
from chores.models import Chore
from django.contrib import admin
class ChoreAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['description', 'frequency', 'person']})
]
admin.site.register(Chore, ChoreAdmin)
and I want when I click "add chore" that rather than seeing:
Description: _____
Frequency: ______
Person: _____
I want it to show:
Description: __________ | Frequency: _______ | Person: _____
Is this trivial to do, or would it take a lot of custom effort? And if it is easy, how do I do it?
Thanks!
OP is probably all set, but for new users reading this, refer to: https://docs.djangoproject.com/en/dev/ref/contrib/admin/
Basically following part in above link:
The field_options
dictionary can have the following keys:
fields
: A tuple of field names to display in this fieldset. This key is required.
Example:
{
'fields': ('first_name', 'last_name', 'address', 'city', 'state'),
}
Just like with the fields
option, to display multiple fields on the same line, wrap those fields in their own tuple. In this example, the first_name
and last_name
fields will display on the same line:
{
'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
}
这篇关于如何在Django管理员中以表格格式显示添加模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!