[英]jquery autocomplete tagging
Can any one tell me how to use tagging auto-complete in django templates? 谁能告诉我如何在Django模板中使用标记自动完成功能?
I have done this in django admin interface but i am confused to how to do it in the template. 我已经在django管理界面中做到了这一点,但是我对如何在模板中做到这一点感到困惑。
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! 在我的url.py上,我在urlparttern元组上有此名称,它可以是任何内容,具体取决于您要如何连接视图和url!
(r'^taglookup/$', 'twine.twineapp.views.tag_lookup')
and on my views.py i have the tag_lookup view implemented as: 在我的views.py上,我将tag_lookup视图实现为:
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. PS:我正在使用Tagging包,这就是为什么我在上面的代码中有Tag对象。
You could use my django-tagging-autocomplete reusable app and take advantage of provided TagAutocomplete form widget. 您可以使用我的django-tagging-autocomplete可重用应用程序,并利用提供的TagAutocomplete表单小部件。 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. 请注意,该应用程序要求您对标签使用django-tagging。 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. 您还需要在模板的
<head>
部分中放入{{ form.media }}
(其中“ form”是表单的名称),以允许小部件包括其JavaScript文件。
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. 其中search_stuff返回符合条件的所有项目的文本列表。 Does that help?
有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.