App enabling the use of jQuery UI autocomplete widget for ModelChoiceFields with minimal configuration required.
Project description
Django Simple Autocomplete
App enabling the use of jQuery UI autocomplete widget for ModelChoiceFields with minimal configuration required.
Installation
Install or add django-simple-autocomplete to your Python path.
Add simple_autocomplete to your INSTALLED_APPS setting.
Add (r’^simple-autocomplete/’, include(‘simple_autocomplete.urls’)) to urlpatterns.
Ensure jQuery core, jQuery UI Javascript and jQuery UI CSS is loaded by your templates. Your jQueryUI bundle must include the autocomplete widget described at http://docs.jquery.com/UI/Autocomplete.
Usage
Django by default renders a select widget (a.k.a. combobox or dropdown) for foreign key fields. You can change the widget to an autocomplete widget by adding the model to the SIMPLE_AUTOCOMPLETE_MODELS tuple in your settings file. For instance, to use the autocomplete widget when selecting a user do:
SIMPLE_AUTOCOMPLETE_MODELS = ('auth.user',)
For more parameters set the SIMPLE_AUTOCOMPLETE dictionary in your settings file. The example above then becomes:
SIMPLE_AUTOCOMPLETE = {'auth.user': {'threshold':10}}
The dictionary format allows arbitrary parameters to be introduced in future. Parameter threshold indicates the minimum number of options required before the widget is rendered as an autocomplete widget. If the threshold is not met the default widget is rendered.
The product attempts to use a field title for filtering and display in the list. If the model has no field title then the first CharField is used. Eg. for the user model the field username is used.
The widget can be used implicitly in a form. The declaration of ModelChoiceField is all that is required:
class MyForm(forms.Form): user = forms.ModelChoiceField(queryset=User.objects.all(), initial=3)
The widget can be used explicitly in a form. In such a case you must provide an URL which returns results as JSON with format [(value, label), (value, label),…]. The initial and initial_display parameters are only required if there is a starting value:
from simple_autocomplete.widgets import AutoCompleteWidget class MyForm(forms.Form): user = forms.ModelChoiceField( queryset=User.objects.all(), initial=3, widget=AutoCompleteWidget( url='/custom-json-query', initial_display='John Smith' ) )
The ability to specify an URL for the widget enables you to hook up to other more advanced autocomplete query engines if you wish.
Changelog
0.2
Clear autoselect helper in some cases for cleaner UI.
Use object string representation for display and not lookup fieldname.
0.1
Add autocomplete widget for multiple selections
Threshold setting to determine when to show autocomplete widget instead of normal widget
0.0.1
Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for django-simple-autocomplete-0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1874a02f43ebc43eda67cd6b6983213cf274994d36a47cf0bb6c21b6b1fbe86e |
|
MD5 | 0ea90b6a87e93ee226fa6f1ec0d38a5a |
|
BLAKE2b-256 | e96be7bc35714299f2dc0c82ef02752c22793aa54cad50e22a9e091c9327e705 |
Hashes for django_simple_autocomplete-0.2-py2.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c81a5fcdfbd16b1f3ad2cae27c396c51dcadcd64539adc1ebba16dafbc73229 |
|
MD5 | 3c4ac7d4895405a843cca8a5f22065f5 |
|
BLAKE2b-256 | afe7dd170d022dbe3ef6ca452e7418396377256ba02089bbe1e71273b4a66e49 |
Hashes for django_simple_autocomplete-0.2-py2.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b2399eb42fa6f558b508d8304dbe6c9d7120fc0a79b68e1a44e7d6b2146ca45 |
|
MD5 | 62fea1a7556746cf57f73724903624bf |
|
BLAKE2b-256 | 512bf8bbd0d234af55bd3d124a1ce2644fcd10fbd0565b910fc8005bcc3af6e3 |