How can I limit django-taggit to accept only lowercase words?

I am using django-taggit. I would like to have all the tags lowercase and also set the range for tag numbers (e.g. between 1 and 5, same as stackoverflow). Is there a way to do this with django-taggit? Thanks!

+4
source share
3 answers

You might want to check out this thread. https://github.com/shacker/django-taggit has FORCE_LOWERCASE parameter.

+3
source

This is pretty easy to do with django-taggit. Subclass TagBase and force string restrictions in the save method. The rest is the boiler point, so the TaggableManager can use your subclass.

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) 

You can also set a range limit for tag numbers in the save method.

+2
source

An old question, but now there is the following setting for handling case-insensitive tags:

 TAGGIT_CASE_INSENSITIVE = True 
+2
source

All Articles