https://github.com/redhog/django-autocomplete
Github mirror of django-autocomplete
https://github.com/redhog/django-autocomplete
Last synced: 2 months ago
JSON representation
Github mirror of django-autocomplete
- Host: GitHub
- URL: https://github.com/redhog/django-autocomplete
- Owner: redhog
- Created: 2013-05-07T23:27:50.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2013-10-09T14:29:52.000Z (almost 13 years ago)
- Last Synced: 2025-10-03T13:48:20.559Z (10 months ago)
- Language: JavaScript
- Homepage: http://code.google.com/p/django-autocomplete/
- Size: 140 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
# AutoComplete for ForeignKey and ManyToManyField
uses same syntax as the search for django-admin
requirements
* query.js (http://jquery.com/)
* query.autocomplete.js
## Example
use a fairly simple
*models.py*
class Type (models.Model):
title = models.CharField()
class Celebrity(models.Model):
name = models.CharField()
class Film(models.Model):
type = models.ForeignKey( Type )
director= models.ManyToManyField( Celebrity, related_name="director")
actor = models.ManyToManyField( Celebrity, related_name="actor")
in m2m field need to specify related_name
*admin.py*
from apps.autocomplete.widgets import *
class FilmAdmin(AutocompleteModelAdmin):
related_search_fields = {
'type': ('title',),
'actor': ('^name',),
'director': ('^name',),
}
admin.site.register( Film, FilmAdmin )
"related_search_fields" parameter is used to specify on what fields you want to search 'actor' and 'director' ties are the names given in "related_name" query syntax is similar to [searching in admin panel](http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.search_fields)
I use the " 'actor': ('^name',) " operator ^ means the beginning of the field. and eventually will be formed about the substitution request form For example, if related_search_fieldsis set to ('^name',') and a user searches for john lennon, Django will do the equivalent of this SQL WHERE clause:
WHERE name ILIKE 'john%' AND name ILIKE 'lennon%'