Djpcms comes with autocomplete functionalities out of the box. The auto-complete is associated with a database model and its registered djpcms.views.appsite.ModelApplication.
Lets say we have the following model (from vinoweb example):
class Grape(models.Model):
name = models.CharField(unique = True, max_length = 200)
extended = models.CharField(blank = True, max_length = 500)
The four points to follow to have auto-complete working for a given model:
Your model application must have a valid djpcms.views.appsite.ModelApplication.search_fields list specified (by default this attribute is None).
Your model application must have the djpcms.views.appview.AutocompleteView:
from djpcms.views import appsite,appview
class GrapeApp(appsite.ModelApplication):
search_fields = ['name','extended']
autocomplete = appview.AutocompleteView(display = 'name')
Register your application as usual:
appsite.site.register('/grape/', GrapeApp, model = Grape)
When using the model in Forms, import from djpcms.forms and not django.forms:
from djpcms import forms
class WineForm(forms.Form):
grape = forms.ModelChoiceField(queryset = Grape.objects.all())
name = forms.CharField()
There is also a tagging autocomplete functionality.