views:

1433

answers:

4

Is there anybody out there who have used Django and JQuery Autocomplete? Am stuck on this and i will highly appreciate to see how someone else has done this! especially without using the AutocompleteWidget!

Gath

+7  A: 

Not sure what's the problem with the widget, haven't used it: i just rolled my own.

So if you want to copy it feel free:

http://buggato.com/site_media/getcities.js

It's used here: http://buggato.com/filter/by/city/ you can try it searching for an Italian city like "Milano".

My python code looks like this:

def city_search(request):
    q = request.GET['q']
    city_list = City.objects.filter(name__istartswith=q).order_by("name")[:10]
    json = serialize("json", city_list)

    return HttpResponse(json, mimetype="application/x-javascript")

It's far from perfect but more than enough for my site.

On another note, why don't you mix and match what works? Use YUI's autocomplete if that works better.

L. De Leo
+1  A: 

There are some easy to follow examples in this GitHub mirror of django-autocomplete.

Ben James
A: 

You'll find value in using Django Piston even for such a small task. It works as a stand-alone app (no funny stuff or serious changes to your app to use it). It allows you to create methods and expose them as JSON. It's a much more extensible way to add AJAX (saves a lot of time later when you decide to add even more AJAX). It's very light weight too.

orokusaki
A: 

some time ago I put together a small tutorial on this, you might find that useful... it's here

magicrebirth