4. Modify urls.py

5. Using it in your models

To use, you need to define a ajax_autocomplete(data) (either in Model or Model.objects) and an ajax_str.

Below is an example usage in some models:

fromdjango.dbimport models
fromajaxfkey.fieldsimport AjaxForeignKey
# notice the manager, we can create a staticmethod in Poll if we wanted.classPollManager(models.Manager):defajax_autocomplete(self, data):returnself.filter(question__istartswith = data).order_by('question')classPoll(models.Model):
question = models.CharField(maxlength=200)
pub_date = models.DateTimeField('date published')# set the manager
objects = PollManager()# this is how it displays in the autocompletion...should be related to # how the person filters abovedefajax_str(self):returnself.question
classChoice(models.Model):# notice it's the same syntax as models.ForeignKey
poll = AjaxForeignKey(Poll)
choice = models.CharField(maxlength=200)
votes = models.IntegerField()