如何在django中关联每个模型的多种类型的标签 [英] How to associate multiple types of tags per model in django

查看:99
本文介绍了如何在django中关联每个模型的多种类型的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不太喜欢django,试图找到最好的办法,而不是自己写一切。我正在使用一个模型,我需要多种类型的标签与模型相关联,然后我想使用多个过滤条件检索对象。我看到在django-tagging标签是存储每个模型,所以我认为不可能有多个标签每个模型。例如:

  class Place(model):
category = TagField()#fun,play,learn,relax
sport = TagField()#划船,狩猎,钓鱼

有可能使用django标签?我错过了一些东西,因为这对我来说看起来很常见。

解决方案

似乎你在说所谓的>机器标签。这些是具有命名空间和/或值的标签。 (Flickr使用这种方法:它允许我们使用即将到来标记照片:event = 81334 ,并将该标签显示为即将到来事件的链接。)



2007年提交的django-tagging有一个问题:请参阅code.google.com/p/django-tagging/issues/detail?id=14.



不幸的是,核心维护者没有评论。然而,GregorMüllegger在这里提供了一个'machinetags'分支:
https://code.launchpad.net/~gregor-muellegger/django-tagging/machinetags/



主要是与django-tagging trunk(最新的提交)同步,但一些提交缺失)。一年前我记得自己在使用该分支机构的一些项目上工作;它工作正常阅读有关分支的文档和有关更多详细信息的问题的意见。


I am little new to django and trying to find best ways to do things instead of writing everything myself. I am working on a model where I need multiple types of tags to be associated with a model and then I want to retrieve the objects using multiple filtering criteria. I see that in django-tagging tags are stored per model so I think its not possible to have multiple tags per model. Ex:

   class Place( model ):
     category = TagField() # fun, play, learn, relax
     sport    = TagField() # boating, hunting, fishing

Is it possible to do this using django-tagging ? Am I missing something since this looks pretty common usecase to me.

解决方案

Seems like you're talking about so-called machine tags. These are tags with namespaces and/or values. (Flickr uses this approach: it allows us to tag photo with, say, upcoming:event=81334, and will display this tag as a link to Upcoming event.)

There is an issue for django-tagging, filed back in 2007: see code.google.com/p/django-tagging/issues/detail?id=14.

No comments by core maintainers, unfortunately. However, there's a ‘machinetags’ branch mantained by Gregor Müllegger here: https://code.launchpad.net/~gregor-muellegger/django-tagging/machinetags/.

It's mostly in sync with the django-tagging trunk (the latest commit a number of commits is missing though). I remember myself working on some project using that branch about a year ago; it worked fine. Read the documentation on branch and comments on the issue for more details.

这篇关于如何在django中关联每个模型的多种类型的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆