An open API service indexing awesome lists of open source software.

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

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!