Code Monkey home page Code Monkey logo

django-searchable-select's Introduction

django-searchable-select

Build Status Coverage Status

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

After

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', many=True)
            }
    
    
    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!

Supported versions

  • Python 2.7.x: Django 1.7, 1.8, 1.9, 1.10
  • Python 3.x: Django 1.8, 1.9, 1.10

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.

django-searchable-select's People

Contributors

and3rson avatar andersondunai avatar michalwols avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.