如何使用 django-tagging 过滤标签?
我正在使用 django 应用程序 django-tagging,并尝试过滤掉某些标签以进行简单的标签搜索。
变量“标签”是我正在搜索的某个标签的文本。 “Widget”是与标签关联的模型。
tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains=tag))
上面的代码可以工作。它返回包含该标签的标签列表,但它也返回与使用该标签的小部件关联的其他标签。
例如,我有一个小部件:A,A有标签:django、python、mysql。 如果我对“django”进行简单搜索:
tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains='django'))
标签将返回此列表:[(标签:django),(标签:python),(标签:mysql)]
我只希望它返回:[(标签:django)]
我该怎么做?
I'm using the django app django-tagging and I'm trying to filter out certain tags for a simple tag search.
the variable 'tag' is text of some tag I am searching for.
'Widget' is the model associated with the tags.
tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains=tag))
The code above sort of works. It returns a list of tags which contain the tag, but it also returns other tags associated with widgets that use that tag.
For example, I have a widget: A, and A has tags: django, python, mysql.
If I do a simple search for 'django':
tags = Tag.objects.usage_for_model(Widget, counts=True, filters=dict(tags__icontains='django'))
tags will return this list: [(Tag: django), (Tag: python), (Tag: mysql)]
I only want it to return: [(Tag: django)]
How do I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
迟到总比不到好?
Better late than never?