1👍
I usually implement this at the form level:
def clean_tags(self):
"""
Force all tags to lowercase.
"""
tags = self.cleaned_data.get('tags', None)
if tags:
tags = [t.lower() for t in tags]
return tags
It really depends on how you look at it. I’m happy with solution because I consider it a validation problem. If you consider it a data integrity problem, I can understand why you’d want to do it at the model level. At which point your best bet is to subclass the taggit modules to a point that you can override Tag.save().
0👍
In the appname –> utils file, for eg:(blog –> init.py), define a function as follows:
def comma_splitter(tag_string):
"""convert each tag into lowercase"""
return [t.strip().lower() for t in tag_string.split(‘,’) if t.strip()]
And then, in the settings.py file, define and override the default taggit settings as:
TAGGIT_TAGS_FROM_STRING = ‘blog.init.comma_splitter’
- [Answer]-Django filter for URL that consists of two variables
- [Answer]-Django Assign Value To Model Form Before Validate
- [Answer]-How do I create pretty url from the GET parameters in Django?
Source:stackexchange.com