I want to change the way that the "+" icon for the foreign key in the admin site is shown.
I found that the widget that prints the code is RelatedFieldWidgetWrapper
that is in django/contrib/admin/widgets.py
.
So I wrote my version of this class and I changed its render
function.
But now how can I use it? I mean... in the definition of my model do I have to use the formfield_overrides
in this way?
formfield_overrides = {
models.ForeignKey: {'widget': customRelatedFieldWidgetWrapper},
}
I think that this is not the right way, because that widget is not the one that manage the whole foreign key, but only the "+" icon. Am I wrong?
Thanks a lot.
You would need to create custom ModelForm for ModelAdmin and override widget there.
Example code:
I approached this slightly differently by monkey-patching the widget - that way the change is reflected in all forms and you're not monkeying around with django's source code.
I ran into this as I was working on customizing yawd admin, a very nice Twitter-Bootstrap skin for admin interface. Now all my icons are jazzed up.