python - Changing default django admin widget site wide -
i want modify widget used models.urlfield
include dropdown internal links in site (similar any-urlfield
detected sitemap).
i want have every external app uses models.urlfield
use custom widget , not have redefine each individual app formfield_overrides
.
i looked django/contrib/admin/options.py
, found
formfield_for_dbfield_defaults = { ... models.textfield: {'widget': widgets.admintextareawidget}, models.urlfield: {'widget': widgets.adminurlfieldwidget}, models.integerfield: {'widget': widgets.adminintegerfieldwidget}, models.bigintegerfield: {'widget': widgets.adminbigintegerfieldwidget}, ... }
essentially change default if possible. how go changing default widget field in django admin site wide.
why not update dictionary? place code admin.py
file.
from django.contrib.admin import options django.db import models django.forms import widgets options.formfield_for_dbfield_defaults[models.urlfield] = { 'widget': widgets.textinput}
update: make work should place line @ top of admin.py
before admin.site.register()
calls. need move app such admin.py
somewhere @ top of installed_apps
list. change affect apps loaded after mentioned app.
Comments
Post a Comment