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.
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',)
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.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 Distribution
Hashes for django-simple-autocomplete-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 00a027048f8bd0f5cefff8f2c0602e2da6f951432f5a7f32c93404342518fd40 |
|
MD5 | 163ee480e4cea4d956e100d05eb71438 |
|
BLAKE2b-256 | 106c8f265a92d661150a484b27d39f934c343b86af2288775eddda4e9e767b7d |
Hashes for django_simple_autocomplete-0.0.1-py2.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a69bfdc2ba2e482f3279fb4778085473a2c33b0585762e63b8af8313a5744ab6 |
|
MD5 | 412d9251a506a721f7d5d1e39453ea10 |
|
BLAKE2b-256 | 933c4db577f1b149072a72916261c43118109c7015c9927c86836383ef6af478 |