开发者

jquery autocomplete tagging

Can any one tell me how to use tagging开发者_StackOverflow auto-complete in django templates?

I have done this in django admin interface but i am confused to how to do it in the template.

Thanks in advance


In my template i have this code:

$(document).ready(function(){
  $("#tags1").autocomplete("/taglookup/", {
        width: 320,
        multiple: true,
        multipleSeparator: " "
         });
   }

and on my url.py i have this on the urlparttern tuple, it can be anything depending on how you want to wire you views and urls!

(r'^taglookup/$', 'twine.twineapp.views.tag_lookup')

and on my views.py i have the tag_lookup view implemented as:

def tag_lookup(request):
    # Default return list
    results = []
    if request.method == "GET":
        if request.GET.has_key(u'q'):
            value = request.GET[u'q']
            # Ignore queries shorter than length 2
            if len(value) > 2:
               TI = Tag.objects.filter(name__startswith=value.lower())
               results = [ x.name for x in TI]
    return HttpResponse('\n'.join(results), mimetype='text/plain')

PS: Am using the Tagging package, that's why i have the Tag object in the above code.


You could use my django-tagging-autocomplete reusable app and take advantage of provided TagAutocomplete form widget. You can find out more about using the widget in the documentation under "Using the form widget".

Please note that the app requires you use django-tagging for your tags. You also need to put {{ form.media }} (where "form" is the name of your form) inside the <head> section in your template, to allow the widget to include it's JavaScript files.


This is from a template where I implemented autocomplete

$(document).ready(function() {

    $("#searchbox").autocomplete('/search_stuff/', {
        width: 300,
        multiple: false,
        matchContains: true,
        delay: 900,
        extraParams: {
               s: function() { return $("#status").val(); }
        }
});

Where search_stuff return a text list of all the items that fitted the criteria. Does that help?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜