Skip to main content

django-searchable-select - a better and faster multiple selection widget with suggestions for Django

Project description

django-searchable-select

A better and faster multiple selection widget with suggestions for Django

What is this?

This plugin provides a replacement for standard multi-choice select on Django admin pages.

You can use this as custom widget for ManyToManyField.

Features

  • Filtering is performed on server side and thus significantly improves performance.

  • Uses Twitter Typeahead to provide suggestion completion.

  • Works great with ManyToMany fields that can be chosen from thousands of thousands of choices, e. g. User - City relations.

Before

Before

Before

After

Before

Before

Installation

  1. Install django-searchable-select.

    $ pip install django-searchable-select
  2. Add ‘searchableselect’ to your settings.

    # settings.py
    
    INSTALLED_APPS = (
        # ...
        'searchableselect',
        # ...
    )
  3. Add URL pattern required for the suggesting engine to your root urls.py.

    # urls.py
    
    urlpatterns = patterns(
        '',
        # ...
        url('^searchableselect/', include('searchableselect.urls')),
        # ...
    )
  4. Use the widget in your model admin class:

    from django import models, forms
    from searchableselect.widgets import SearchableSelect
    from models import Traveler
    
    class TravelerForm(forms.ModelForm):
        class Meta:
            model = Traveler
            exclude = ()
            widgets = {
                'cities_visited': SearchableSelect(model='cities.City', search_field='name')
            }
    
    
    class TravelerAdmin(admin.ModelAdmin):
        form = TravelerForm
    
    admin.site.register(Traveler, TravelerAdmin)

    Remember to always initialize SearchableSelect with three keyword arguments: model, search_field and many.

    • model is the string in form APP_NAME.MODEL_NAME representing your model in the project, e. g. ‘cities.City’

    • search_field is the field within model that will be used to perform filtering, e. g. ‘name’

    • many must be True for ManyToManyField and False for ForeignKey.

Example app

Just run the project from example directory, head to http://127.0.0.1:8000, login as admin/admin and try adding Cats!

Known issues

  • Not tested with empty fields.

Contributing

I’m looking forward to bug reports and any kind of contribution.

License

You are free to use this where you want as long as you keep the author reference. Please see LICENSE for more info.

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-searchable-select-1.4.2.tar.gz (58.6 kB view details)

Uploaded Source

File details

Details for the file django-searchable-select-1.4.2.tar.gz.

File metadata

File hashes

Hashes for django-searchable-select-1.4.2.tar.gz
Algorithm Hash digest
SHA256 95b7575c45387ba8bca9c7427a36f393fd4258cae58283d6d34c5f489e21c064
MD5 61a8be3670fc03201c74c8d963e6fc19
BLAKE2b-256 c47452c21e6343e890bf23107bfde08098d4fe7cc6fc1c6fb4a27bafc40613df

See more details on using hashes here.

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