https://github.com/justquick/django-chosen-ajax
Integrates chosen javascript library with ajax autocomplete functionality into the django admin
https://github.com/justquick/django-chosen-ajax
Last synced: 9 months ago
JSON representation
Integrates chosen javascript library with ajax autocomplete functionality into the django admin
- Host: GitHub
- URL: https://github.com/justquick/django-chosen-ajax
- Owner: justquick
- License: bsd-3-clause
- Created: 2013-07-24T17:42:23.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2022-08-22T13:06:13.000Z (almost 4 years ago)
- Last Synced: 2025-04-25T16:59:30.929Z (about 1 year ago)
- Language: CSS
- Size: 88.9 KB
- Stars: 0
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
:Version: 0.1.0
Overview
==================
.. image:: http://i.imgur.com/wK54oJF.jpg?3
django-chosen-ajax implements the `chosen `_ javascript library into the django admin for select form elements. It also implements ajax autocomplete functionality for form fields which have large numbers of related objects. The library currently uses `jquery `_ and was inspired by `django-chosen `_ and `chosen-ajax `_.
Features
--------
- Integrates `chosen `_ into the admin
- Implements ajax functionality for ModelMultipleChoiceField's
Install
-------
Install with pip
::
pip install git+https://github.com/epicowl/django-chosen-ajax.git#egg=django-chosen-ajax
Add ``chosen`` to your ``INSTALLED_APPS``
Run ``collectstatic``
Compatibility
^^^^^^^^^^^^^
django-chosen-ajax has been tested with
:Django: 1.4, 1.5
:Python: 2.7
:Database: PostgreSQL
Usage
------
Subclass the ChosenAdminForm using the ChosenAjaxField for ajax fields and include the required ``search_fields=('field',)`` where ``field`` is the name of a database field to use for the search lookup.
.. code-block:: python
from chosen.forms import ChosenAdminForm
from chosen.fields import ChosenAjaxField
class PonyForm(ChosenAdminForm):
ponies = ChosenAjaxField(
required=False,
queryset=Pony.objects.all(),
search_fields=('name', 'breed',)
)
class Meta:
model = YourModel
Currently you will also have to add the admin site to your ModelAdmin to make the green add related button work.
.. code-block:: python
from django.contrib import admin
from ponyapp.forms import PonyForm
class PonyAdmin(admin.ModelAdmin):
form = PonyForm
def __init__(self, model, admin_site):
super(PonyAdmin, self).__init__(model, admin_site)
self.form.admin_site = admin_site
You can add as many fields to search_fields as you need, they get combined into a lookup. Everything else is automatic and handled in the ChosenAdminForm.
Hit me up if you have questions or want to contribute!