我用的是django-taggit。我希望所有的标签都是小写的,并为标签编号设置一个范围(比如介于1和5之间,就像stackoverflow一样)。有什么方法可以用django-taggit轻松做到这一点吗?谢谢!
发布于 2011-05-27 04:28:35
你可能想看看这个分支。https://github.com/shacker/django-taggit它有一个FORCE_LOWERCASE设置。
发布于 2011-08-20 16:16:11
使用django-taggit很容易做到。将TagBase子类化并在保存方法中强制执行小写约束。剩下的就是沸点,这样TaggableManager就可以使用你的子类了。
class LowerCaseTag(TagBase):
def save(self, *args, **kwargs):
self.name = self.name.lower()
super(LowerCaseTag, self).save(*args, **kwargs)
class LowerCaseTaggedItem(GenericTaggedItemBase):
tag = models.ForeignKey(LowerCaseTag, related_name="tagged_items")
class YourModel(models.Model):
tags = TaggableManager(through=LowerCaseTaggedItem)您还可以在save方法中强制对标记号进行范围限制。
发布于 2016-01-09 05:28:44
老问题,但现在有以下设置来处理不区分大小写的标签:
TAGGIT_CASE_INSENSITIVE = True如果您希望django-taggit在查找现有标记时不区分大小写,则必须将TAGGIT_CASE_INSENSITIVE设置为True (默认情况下为False):
TAGGIT_CASE_INSENSITIVE =真
来源:https://django-taggit.readthedocs.io/en/latest/getting_started.html
https://stackoverflow.com/questions/6144498
复制相似问题