Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a custom inline admin widget in Django?

Tags:

This is easy for non-inlines. Just override the following in the your admin.py AdminOptions:

def formfield_for_dbfield(self, db_field, **kwargs):
    if db_field.name == 'photo':
        kwargs['widget'] = AdminImageWidget()
        return db_field.formfield(**kwargs)
    return super(NewsOptions,self).formfield_for_dbfield(db_field,**kwargs)

I can't work out how to adapt this to work for inlines.

like image 373
Andy Baker Avatar asked Jan 11 '09 17:01

Andy Baker


1 Answers

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.

like image 117
Carl Meyer Avatar answered Oct 12 '22 13:10

Carl Meyer