riccardo-forina/django-admin-bootstrapped — pull request #49 by jmagnusson (2013-05-28 10:26:54+00:00)
Title: Generic lookups in admin

The one thing that was missing from this project to be a worthy replacement to `grappelli` imo. No need for new urls or views, just some jquery xhr parsing magic.

![Example image](http://i.imgur.com/vipTtSs.png)

All that needs to be done is change the admin widget with either `formfield_overrides` like this:

```python
from django_admin_bootstrapped.widgets import GenericContentTypeSelect

class SomeModelAdmin(admin.ModelAdmin):
formfield_overrides = {
models.ForeignKey: {'widget': GenericContentTypeSelect},
}
```

Or if you want to be more specific:

```python
from django_admin_bootstrapped.widgets import GenericContentTypeSelect

class SomeModelAdmin(admin.ModelAdmin):
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'content_type':
kwargs['widget'] = GenericContentTypeSelect
return super(SomeModelAdmin, self).formfield_for_dbfield(db_field, **kwargs)
```

If you decide on using `formfield_overrides` [you should be aware of its limitations with relation fields](https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.formfield_overrides).