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


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.


Since Django 1.1, formfield_overrides is also working

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


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