Skip to main content

Edit ForeignKey, ManyToManyField and CharField in Django Admin using jQuery UI AutoComplete.

Project description

Edit ForeignKey, ManyToManyField and CharField in Django Admin using jQuery UI AutoComplete

Build Status PyPI version

This Django app glues Django Admin, jQuery UI together to enable searching and managing ForeignKey and ManyToMany relationships.

At the time it was created Django did not have any way to do this, and this solution glued together some technologies of the day.

If you are building a new project then you should not use this.

Django has built in support now:





pip install django-ajax-selects

Add the app:

    'ajax_select',  # <-   add the app

Include the urls in your project:

from django.urls import path
from django.conf.urls import include

from django.conf.urls.static import static
from django.contrib import admin
from django.conf import settings
from ajax_select import urls as ajax_select_urls


urlpatterns = [
    # This is the api endpoint that django-ajax-selects will call
    # to lookup your model ids by name
    path("admin/lookups/", include(ajax_select_urls)),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Quick Usage

Define a lookup channel:

# yourapp/
from ajax_select import register, LookupChannel
from .models import Tag

class TagsLookup(LookupChannel):

    model = Tag

    def get_query(self, q, request):
        return self.model.objects.filter(name__icontains=q).order_by('name')[:50]

    def format_item_display(self, item):
        return u"<span class='tag'>%s</span>" %

Add field to a form:

# yourapp/
from ajax_select.fields import AutoCompleteSelectMultipleField

class DocumentForm(ModelForm):

    class Meta:
        model = Document

    tags = AutoCompleteSelectMultipleField('tags')

This will now work in the Django Admin.

To use a form outside, be sure to include on the template where you place the form:

{{ }}
{{ form }}

Read the full documention here: outside of the admin

Fully customizable

  • Customize search query
  • Query other resources besides Django ORM
  • Format results with HTML
  • Customize styling
  • Customize security policy
  • Add additional custom UI alongside widget
  • Integrate with other UI elements elsewhere on the page using the javascript API
  • Works in Admin as well as in normal views

Assets included by default 3.7.1 1.13.2

Customize jquery

To use a custom jQuery UI theme you can set:

AJAX_SELECT_JQUERYUI_THEME = "/static/path-to-your-theme/jquery-ui-min.css"

If you need to use a different jQuery or jQuery UI then turn off the default assets:


and include jquery and jquery-ui yourself, making sure they are loaded before the Django admin loads.


  • Django >=3.2
  • Python >=3.10


Many thanks to all contributors and pull requesters !


Dual licensed under the MIT and GPL licenses:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_ajax_selects-3.0.0.tar.gz (428.2 kB view hashes)

Uploaded Source

Built Distribution

django_ajax_selects-3.0.0-py3-none-any.whl (445.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page