[Fixed]-How do I add a custom inline admin widget in Django?

12👍

It works exactly the same way. The TabularInline and StackedInline classes also have a formfield_for_dbfield method, and you override it the same way in your subclass.

8👍

Since Django 1.1, formfield_overrides is also working

formfield_overrides = {
    models.ImageField: {'widget': AdminImageWidget},
}
👤luc

3👍

Working example:

class PictureInline(admin.StackedInline):
    model = Picture_Gallery
    extra = 3
    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name == 'name':
            kwargs['widget'] = MyWidget()
        return super(PictureInline,self).formfield_for_dbfield(db_field,**kwargs)

Leave a comment