{"id":13448820,"url":"https://github.com/and3rson/django-searchable-select","last_synced_at":"2025-04-09T15:09:04.671Z","repository":{"id":37773899,"uuid":"48234852","full_name":"and3rson/django-searchable-select","owner":"and3rson","description":"A better and faster multiple selection widget with suggestions","archived":false,"fork":false,"pushed_at":"2022-06-25T11:49:10.000Z","size":117,"stargazers_count":108,"open_issues_count":14,"forks_count":29,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T15:08:57.323Z","etag":null,"topics":["choice","django","django-searchable-select","python","widget"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/and3rson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-12-18T12:45:25.000Z","updated_at":"2025-03-07T02:38:39.000Z","dependencies_parsed_at":"2022-08-18T05:50:09.704Z","dependency_job_id":null,"html_url":"https://github.com/and3rson/django-searchable-select","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/and3rson%2Fdjango-searchable-select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/and3rson%2Fdjango-searchable-select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/and3rson%2Fdjango-searchable-select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/and3rson%2Fdjango-searchable-select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/and3rson","download_url":"https://codeload.github.com/and3rson/django-searchable-select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055282,"owners_count":21040157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["choice","django","django-searchable-select","python","widget"],"created_at":"2024-07-31T06:00:21.854Z","updated_at":"2025-04-09T15:09:04.641Z","avatar_url":"https://github.com/and3rson.png","language":"Python","funding_links":[],"categories":["Fields","Python","数据项"],"sub_categories":[],"readme":"# django-searchable-select\n\n[![Build Status](https://travis-ci.org/and3rson/django-searchable-select.svg)](https://travis-ci.org/and3rson/django-searchable-select) [![Coverage Status](https://coveralls.io/repos/github/and3rson/django-searchable-select/badge.svg?branch=master)](https://coveralls.io/github/and3rson/django-searchable-select?branch=master)\n\nA better and faster multiple selection widget with suggestions for Django\n\n## This project is looking for maintainers!\n\nPlease open an issue to request write access.\n\n# What is this?\n\nThis plugin provides a replacement for standard multi-choice select on Django admin pages.\n\nYou can use this as custom widget for `ManyToManyField`.\n\n# Features\n\n  - Filtering is performed on server side and thus significantly improves performance.\n  - Uses `Twitter Typeahead` to provide suggestion completion.\n  - Works **great** with ManyToMany fields that can be chosen from thousands of thousands of choices, e. g. `User - City` relations.\n\n### Before\n\n![Before](https://habrastorage.org/files/dd9/f17/87e/dd9f1787e0dd4e05826fdde08e270609.png)\n\n### After\n\n![Before](https://habrastorage.org/files/db2/c87/460/db2c87460992470e9d8e19da307c169d.png)\n\n# Installation\n\n1. Install `django-searchable-select`.\n\n    ```sh\n    $ pip install django-searchable-select\n    ```\n\n2. Add 'searchableselect' to your settings.\n\n    ```python\n    # settings.py\n\n    INSTALLED_APPS = (\n        # ...\n        'searchableselect',\n        # ...\n    )\n    ```\n\n3. Add URL pattern required for the suggesting engine to your root `urls.py`.\n\n    ```python\n    # urls.py\n\n    urlpatterns = patterns(\n        '',\n        # ...\n        url('^searchableselect/', include('searchableselect.urls')),\n        # ...\n    )\n    ```\n\n4. Use the widget in your model admin class:\n\n    ```python\n    from django import models, forms\n    from searchableselect.widgets import SearchableSelect\n    from models import Traveler\n\n    class TravelerForm(forms.ModelForm):\n        class Meta:\n            model = Traveler\n            exclude = ()\n            widgets = {\n                'cities_visited': SearchableSelect(model='cities.City', search_field='name', many=True, limit=10)\n            }\n\n\n    class TravelerAdmin(admin.ModelAdmin):\n        form = TravelerForm\n\n    admin.site.register(Traveler, TravelerAdmin)\n    ```\n\n    Remember to **always** initialize `SearchableSelect` with three keyword arguments: `model`, `search_field` and `many`.\n\n    - `model` is the string in form `APP_NAME.MODEL_NAME` representing your model in the project, e. g. 'cities.City'\n    - `search_field` is the field within model that will be used to perform filtering, e. g. 'name'\n    - `many` must be `True` for `ManyToManyField` and `False` for `ForeignKey`.\n    - `limit` (optional) specifies the maximum count of entries to retrieve.\n\n# Example app\n\nJust run the project from `example` directory, head to http://127.0.0.1:8000, login as `admin`/`admin` and try adding Cats!\n\n# Supported versions\n\n  - Python 2.7.x: Django 1.7, 1.8, 1.9, 1.10\n  - Python 3.x: Django 1.8, 1.9, 1.10, 2.0\n\n# Testing\n\nIn order to support multiple Django and Python versions we use:\n\n  - `py.test` - test runner\n  - `tox` - handy tool to test app with different versions of Pythons \u0026 libraries\n  - `selenium`\n  - `coverage`\n\nInstall them via `pip install -r requirements/dev.txt`\n\nTo test things in specific environment, run the following commands:\n\n```sh\n# Clear previous coverage data.\ncoverage erase\n\n# This command can be ran multiple times.\ntox -e \u003cpython_ver\u003e-\u003cdjango_ver\u003e\n# Possible python_ver values: `py27`, `py36`\n# Possible django_ver values: `17`, `18`, `19`, `110`, '20'\n# Values can be comma-separated, e. g. `-e py27-17,py27-18,py36-18`\n# If you omit `-e ...` parameter, all environments will be tests.\n# Also - not problems with running this within a virtualenv.\n# Check tox.ini for these values.\n\n# Run this once all tests passed on all environment.\ncoverage combine\n\n# Render HTML with coverage info.\ncoverage html\n# ...or simply display % of covered SLOC for each file.\ncoverage report\n```\n\nTo add a new Django version for testing, add it into `tox.ini`, lines 3-4.\n\nWhy do we need `tox` and `coverage combine`? Because different versions of Python \u0026 libraries lead to different code execution: for example, consider this code:\n\n```python\nimport sys\nif sys.version_info.major == 2:\n    foo = 'spam'  # Not covered in Python 3.x, leads to coverage \u003c 100%\nelse:\n    foo = 'eggs'  # Not covered in Python 2.x, leads to coverage \u003c 100%\n```\n\nUsing `tox` and `coverage combine` we're able to \"merge\" coverage info from across different environments.\n\n# Known issues\n\n  - Not tested with empty fields.\n  - Tests sometimes fail randomly due to some Selenium timeout issue. Weird.\n\n# Contributing\n\nI'm looking forward to bug reports and any kind of contribution.\n\n# License\n\nYou are free to use this where you want as long as you keep the author reference.\nPlease see LICENSE for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fand3rson%2Fdjango-searchable-select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fand3rson%2Fdjango-searchable-select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fand3rson%2Fdjango-searchable-select/lists"}