This provides a quick-and-dirty way to override some of the Field options for use in the admin. formfield_overrides is a dictionary mapping a field class to a dict of arguments to pass to the field at construction time.
看看这个例子:
from django.db import models
from django.contrib import admin
# Import our custom widget and our model from where they're defined
from myapp.widgets import RichTextEditorWidget
from myapp.models import MyModel
class MyModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.TextField: {'widget': RichTextEditorWidget},
}
您可以尝试将您的字段添加到管理员py公司名称:
你会得到一个漂亮的搜索按钮
您正在寻找:
ModelAdmin.formfield_overrides
看看这个例子:
你只需要选一个教授还是多个教授? 下拉列表的生成是因为您在模型中使用了
professor = models.ForeignKey(Professor)
。ForeignKey意味着单选,但是示例widget意味着多个选择。所以你的意图不太清楚。 通过下拉列表,您还可以通过键入第一个字母来选择选项。在相关问题 更多 >
编程相关推荐