1、django tagging app安装:html
pip install django-taggingdjango
或者app
easy_install django-taggingspa
2、在项目中的使用:code
''' 引入tagging相关模块 '''htm
from tagging.fields import TagField
from tagging.models import Tag
ip
class cases(models.Model):
name = models.CharField(u'做品名', max_length=20)
tags = TagField()unicode
def get_tags(self):
return Tag.objects.get_for_object(self)
def update_tags(self,tag_names):
Tag.objects.update_tags(self,tag_names)
def remove_all_tags(self):
Tag.objects.update_tags(self,None)
def __unicode__(self):
return u'%s' % self.namerem
get_tags方法:获取该model的全部tags,以list的方式返回get
update_tags方法:更新该model的全部tags,以list方式传入须要保存的全部tags
remove_all_tags方法:删除该model的全部tags(由于没有发现tagging更好的删除方法,暂用这个代替)
(这个只是初步的总结,后续可能继续更新;有问题欢迎留言交流)