问题描述
新手Django问题:我希望Django管理员在多选择小部件中显示更多行选项。我有一个非常长的列表来选择,默认的4行不方便,特别是滚动时。现在,该小部件呈现为选择多个,但我希望它选择multiple size =12。理想情况下,这应该是针对特定的字段,但是我可以使用相同大小属性的所有字段进行渲染。
那么Django中哪些地方会改变呢?
我在admin.py中设置了所有ManyToManyField项目的毛毯尺寸,例如:
来自django.contrib的 从django.forms导入导入
从django.db导入模型中选择多元
导入模型
从模型导入*
类RiverAdmin(admin.ModelAdmin):
formfield_overrides = {models.ManyToManyField:{'widget':SelectMultiple(attrs = {'size':'10'}) },}
admin.site.register(River,RiverAdmin)
Newbie Django question: I'd like the Django admin to display more rows of choices in the multi-select widget. I have an extremely long list to select from and the default 4 rows just isn't convenient, especially when scrolling.
Right now, that widget is rendered as select multiple but I'd like it to be select multiple size="12". Ideally this should be for specific fields, but I can live with all fields rendering with the same size attribute.
So where would be the optimal place in Django to change that?
I did this in the admin.py by setting a blanket size for all ManyToManyField items, for instance:
from django.contrib import admin
from django.forms import SelectMultiple
from django.db import models
from models import *
class RiverAdmin(admin.ModelAdmin):
formfield_overrides = { models.ManyToManyField: {'widget': SelectMultiple(attrs={'size':'10'})}, }
admin.site.register(River, RiverAdmin)
这篇关于覆盖Django管理员多选小部件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!