Cerin
Cerin

Reputation: 64739

Django raw_id_field style widget for list_filters

Is there a raw_id_field style widget for use when rendering list_filter fields on Django admin changelist pages?

When I add a foreign-key based field to a Django modeladmin list_filter, Django renders every row in the associated table to the right-hand panel in a select box. If that table is large (e.g. if it points to the User table) this tends to dramatically slow down load time as Django works to renders thousands of rows. Even after it finishes rendering, it can be difficult finding your selection in the huge dropdown.

Upvotes: 1

Views: 2176

Answers (1)

Greg
Greg

Reputation: 10342

There's not, but in Django 1.4 the list_filter system was expanded so you can write your own custom filters. See

https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_filter

It'd be trivial to, say, limit the number of Users displayed. Making a raw_id_fields-style filter would be slightly trickier - you'd just need to override the filter template and instead of dispaying a list of links, show a form and submit button.

Upvotes: 1

Related Questions