The Digital Agency for International Development

Django admin with AJAX autocomplete

By Chris Wilson on 13 March 2013

I just ran into the fairly well-known problem where the Django Admin interface loads very slowly when:

  • you edit a record
  • that has a foreign key
  • to a big table (thousands of rows)

Of course this is because Django constructs thousands of objects to populate the dropdown lists.

Searching online for solutions, I found Albert O'Connor's page which references two projects:

I was fairly sure that I wanted AJAX, because I don't want to delay loading of the main page, so I ignored his recommendation to use django-autocomplete (which is apparently out of date anyway) and went with django-ajax-selects.

I was very pleasantly surprised:

  • It's on PyPI, which makes it easy to install a known, stable reference version.
  • It has clear, simple instructions for quick installation.
  • It actually works out of the box very quickly and effectively.
  • It does most of what I want already, especially replacing admin fields.
  • It supports advanced functionality such as searching different fields, and rendering in different ways, very easily.
  • It's not too hard to customise and extend. For example, highlighting the matching phrase in search results.

I'm very happy with it and would recommend anyone looking for autocomplete in Django to try it first.

Thanks to crucialfelix, sjrd (Sébastien Doeraene) and Brian May for developing and maintaining it.