I have a generic ModelAdmin in my admin.py
which replaces some widgets in the admin interface. It serves as a superclass for all my other ModelAdmins. It looks like this:
#in mainapp/admin.py:
from django.contrib import admin
from django.db import models
from suit.widgets import SuitSplitDateTimeWidget
class SuitedUpAdmin(admin.ModelAdmin):
formfield_overrides = {
models.DateTimeField: {
'widget': SuitSplitDateTimeWidget
},
#(...)
}
#(...)
In a different Django app, I use SuitedUpAdmin
as a superclass for a ModelAdmin that also tries to replace some of the widgets:
#in events/admin.py:
from django.contrib import admin
from django.db import models
from suit.widgets import AutosizedTextarea
from mainapp.admin import SuitedUpAdmin
class LocationAdmin(SuitedUpAdmin):
formfield_overrides = {
models.TextField: {'widget': AutosizedTextarea},
}
#(...)
The problem is, when I assign a new value to formfield_overrides
in LocationAdmin
, I lose the previous value inherited from SuitedUpAdmin
. How can I deal with this? The solution I'm currently using is replacing widget instances in a LocationAdmin.render_change_form
method, but I'm looking for more elegant and readable options. I'd like to avoid using ModelForms for this. Looking forward to your suggestions!