• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A better and faster multiple selection widget with suggestions

django-searchable-select

Build Status Coverage Status

A better and faster multiple selection widget with suggestions for Django

This project is looking for maintainers!

Please open an issue to request write access.

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, limit=10)
            }
    
    
    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.
    • limit (optional) specifies the maximum count of entries to retrieve.

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, 2.0

Testing

In order to support multiple Django and Python versions we use:

  • py.test - test runner
  • tox - handy tool to test app with different versions of Pythons & libraries
  • selenium
  • coverage

Install them via pip install -r requirements/dev.txt

To test things in specific environment, run the following commands:

# Clear previous coverage data.
coverage erase

# This command can be ran multiple times.
tox -e <python_ver>-<django_ver>
# Possible python_ver values: `py27`, `py36`
# Possible django_ver values: `17`, `18`, `19`, `110`, '20'
# Values can be comma-separated, e. g. `-e py27-17,py27-18,py36-18`
# If you omit `-e ...` parameter, all environments will be tests.
# Also - not problems with running this within a virtualenv.
# Check tox.ini for these values.

# Run this once all tests passed on all environment.
coverage combine

# Render HTML with coverage info.
coverage html
# ...or simply display % of covered SLOC for each file.
coverage report

To add a new Django version for testing, add it into tox.ini, lines 3-4.

Why do we need tox and coverage combine? Because different versions of Python & libraries lead to different code execution: for example, consider this code:

import sys
if sys.version_info.major == 2:
    foo = 'spam'  # Not covered in Python 3.x, leads to coverage < 100%
else:
    foo = 'eggs'  # Not covered in Python 2.x, leads to coverage < 100%

Using tox and coverage combine we're able to "merge" coverage info from across different environments.

Known issues

  • Not tested with empty fields.
  • Tests sometimes fail randomly due to some Selenium timeout issue. Weird.

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.

More Repositories

1

clay

Awesome standalone command line player for Google Play Music.
Python
157
star
2

django-nameko

Django wrapper for nameko microservice framework.
Python
72
star
3

lilka

Монорепо проєкту "Лілка"
C++
55
star
4

raid

Air Raid Alerts API (Ukraine)
Go
48
star
5

nineapi

Unofficial python client library for *official* 9GAG API. (alpha)
Python
45
star
6

telemux

Flexible message router add-on for go-telegram-bot-api/telegram-bot-api. This is to go-telegram-bot-api as gorilla/mux is to net/http.
Go
42
star
7

graph-bars-font

OTF font with vertical bars for one-line ASCII spectrum analyzers, graphs, etc
Go
29
star
8

foreigner

FFI library for Godot, built with GDNative
C++
25
star
9

mqtt-home

MQTT dashboard app that stores its config in MQTT to easily share your dashboard with your family members and friends.
Java
22
star
10

flake8-colors

ANSI colors highlight for Flake8
Python
14
star
11

node-nameko-client

Node.JS client for Nameko microservice framework.
JavaScript
12
star
12

caveboard

https://youtu.be/Klj2Q3trmW8
Assembly
12
star
13

deck65

Simple SBC based on 65c02s
Assembly
11
star
14

dotfiles

My configs: (neo)vim+lua+lsp+treesitter, wayland (riverwm, yambar, sway, waybar), alacritty, tmux, bash, sonokai/molokai colors and stolen dircolors.
C++
11
star
15

enlightenment

A simple yet fast light engine for Phaser (WebGL render).
HTML
9
star
16

isc

Inter-service communication layer for Python with Django support
Python
9
star
17

telegram-numix-theme

Numix theme for Telegram Destop app. (black, orange & red colors) [BETA]
8
star
18

roulette

VNC/Telnet/RTSP pwn kit: scan & auto-bruteforce
Go
5
star
19

codename

A codename generator inspired by http://projectcodename.com
Python
5
star
20

restic

A loose & flexible REST framework for Sanic. Inspired by Django REST Framework.
Python
5
star
21

pk88

Single-board computer based on KM1810VM88 CPU (Ukrainian clone of Intel 8088).
Assembly
4
star
22

nice65

Code formatter for 6502 assembly (cc65 syntax)
Python
3
star
23

leo80

Z80-based single-board computer
Assembly
3
star
24

picplate

An image templating micro-engine to make generation of dynamic images easier.
Python
3
star
25

and3rson

2
star
26

templize

The lightest DOM-based JavaScript template engine in the world.
HTML
2
star
27

website

JavaScript
2
star
28

nyashbot

Python
2
star
29

telecast

Portable REST/JSON RPC implementation for Django/DRF. Like Fender Telecaster but way cooler.
Python
2
star
30

radical

Multi-transport RPC with asyncio & Django support.
Python
2
star
31

rkon

A lightweight Source RCON command-line client written in Python
Python
2
star
32

ginger

Ginger Is Not a GAL EmulatoR
Python
2
star
33

iorant

An unofficial client for DevRant written in ionic.js
JavaScript
1
star
34

peek

Open-source alternative to Google Keep. We DO have API.
Python
1
star
35

yagni

You are probably gonna need it: a collection of useful Python utilities aggregated over many years of development.
Python
1
star
36

vertabs

Atom plugin that provides vertical tabs over file tree (SublimeText-like)
JavaScript
1
star
37

parts

A library of my KiCad symbols, footprints and 3D models
Makefile
1
star
38

6565

6502 assembler written in 6502 C (CC65)
C
1
star
39

vkplayer

A small VK audio player I made for myself in Python & GTK3.
Python
1
star
40

rule34

Java
1
star
41

ukraine-trident

Makefile
1
star
42

hhh

Just playing around with CS:GO hacking @ Linux.
Python
1
star
43

python-de-test-task

Python Data Engineering Test Task
Python
1
star
44

fm-synth-demo

Simple FM synthesis demonstration made with Godot
1
star