django中使用tagging

来源:互联网 发布:远程视频教学软件 编辑:程序博客网 时间:2024/05/22 17:05

no such table: tagging_tag 處理
 Once you've installed Django Tagging and want to use it in your Django applications, do the following:
 1. Put 'tagging' in your INSTALLED_APPS setting.
 2. Run the command manage.py syncdb .

from tagging.models import Tag
from tagging.models import TaggedItem

基本用法
1.给object 打上tag:
   Tag.objects.update_tags(article, 'python Django') #这里object 是article, 两个tag分别是python Django
给object 添加 tag:
   Tag.objects.add_tag(article, 'web')
清空object的tag:
   Tag.objects.update_tags(article, '')
查看特定object的所有tags:
Tag.objects.get_for_object(article)

2.查看打上特定tag的object
TaggedItem.objects.get_by_model(Article, 'python')

3.from tagging . fields import TagField
如要取出Widget用到的所有tag的代码为:
    tags = Widget.tags.all()

class Widget(models.Model):
   name = models.CharField(max_length=50)
   tags = TagField()

 

 

from tagging.models import TaggedItem

2

查看打上特定tag的object

TaggedItem.objects.get_by_model(Article, 'python')

原创粉丝点击