Overriding Size of Django Admin Multi-select Widget

前端 未结 4 864
梦如初夏
梦如初夏 2020-12-28 17:58

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

4条回答
  •  时光说笑
    2020-12-28 18:59

    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)
    

提交回复
热议问题