Skip to main content

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: https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#django.contrib.admin.ModelAdmin.autocomplete_fields


selecting

selected

Documentation

http://django-ajax-selects.readthedocs.org/en/latest/

Installation

pip install django-ajax-selects

Add the app:

# settings.py
INSTALLED_APPS = (
    ...
    'ajax_select',  # <-   add the app
    ...
)

Include the urls in your project:

# urls.py
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

admin.autodiscover()

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)),
    path("admin/", admin.site.urls),
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Quick Usage

Define a lookup channel:

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

@register('tags')
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>" % item.name

Add field to a form:

# yourapp/forms.py
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 form.media on the template where you place the form:

{{ form.media }}
{{ 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

https://jquery.com/ 3.7.1 https://jqueryui.com/ 1.13.2

Customize jquery

To use a custom jQuery UI theme you can set:

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

https://jqueryui.com/themeroller/

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

# settings.py
AJAX_SELECT_BOOTSTRAP = False

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

Compatibility

  • Django >=3.2
  • Python >=3.10

Contributors

Many thanks to all contributors and pull requesters !

https://github.com/crucialfelix/django-ajax-selects/graphs/contributors/

License

Dual licensed under the MIT and GPL licenses:

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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file django_ajax_selects-3.0.0.tar.gz.

File metadata

  • Download URL: django_ajax_selects-3.0.0.tar.gz
  • Upload date:
  • Size: 428.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1016-azure

File hashes

Hashes for django_ajax_selects-3.0.0.tar.gz
Algorithm Hash digest
SHA256 c5530883aa10e07d5381d148247997f3c8263b91e0a8362b1060274d4d5f28fa
MD5 7df7b85f652b81eb195b77e7c5958ea4
BLAKE2b-256 65b7f0e768e8c5d4e77f650f92d4737173384b6c5019ef95d13b565c1a661f44

See more details on using hashes here.

File details

Details for the file django_ajax_selects-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_ajax_selects-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 445.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.0 Linux/6.2.0-1016-azure

File hashes

Hashes for django_ajax_selects-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97774ae08d5451e47ec2a029d1dce78f80cde187a433ab4d4cb09311aba4a8b9
MD5 7452cddeb62d0855583d948b18c284b0
BLAKE2b-256 9c9cd2919438ae851fb8200221693c660fcc51fb12a17023c62d284987b22dde

See more details on using hashes here.

Release history Release notifications | RSS feed

3.0.3

2 files

3.0.2

2 files

3.0.1

2 files

This release

3.0.0 This release

2 files

2.2.1

1 file

2.2.0

2 files

2.1.0

2 files

2.0.0

1 file

1.9.1

2 files

1.9.0

1 file

1.8.0

2 files

1.7.1

2 files

1.7.0

2 files

1.6.1

2 files

1.6.0

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

1 file

1.4.3

1 file

1.4.2

1 file

1.4.1

1 file

1.4.0

1 file

1.3.6

1 file

1.3.5

1 file

1.3.4

1 file

1.3.3

1 file

1.3.2

1 file

1.3.1

1 file

1.3.0

1 file

1.2.5

1 file

1.2.4

1 file

1.2.3

1 file

1.2.2

1 file

1.2.1

1 file

1.2

1 file

1.1.4

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page