django formfield_for_dbfield : __init__ unexpected keyword argument ‘request’

Quick post:

formfield_for_dbfield examples floating around out there do not work because a lot of them directly call `db_field.formfield(**kwargs)`.

Either remove that call and let the super call take care of it (such as below) or remove `request` from the kwargs by calling kwargs.pop(‘request’)

It turns out the super call now removes the request kwarg before moving further in processing, so if you manually call db_field.formfield(**kwargs) your code will have this extra keyword.

def formfield_for_dbfield(self, db_field, **kwargs): 
    if db_field.attname == 'long_description':
         kwargs['widget'] = CLEditorWidget()
    return super(ProductAdmin, self).formfield_for_dbfield(db_field, **kwargs)

I believe this hook isn’t supposed to be used even, as it’s not really in the docs.

I use it because formfield_overrides is global and doesn’t have per-field granularity and formfield_for_FK/M2M only works for relationships.

If I’m missing a better hook, just let me know. I haven’t really dug around as this is perfectly acceptable.

One thought on “django formfield_for_dbfield : __init__ unexpected keyword argument ‘request’

  1. I do not know if it’s just me or if perhaps everybody else encountering issues with your site. It looks like some of the text on your content are running off the screen. Can someone else please provide feedback and let me know if this is happening to them as well? This may be a issue with my browser because I’ve had
    this happen previously. Many thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s