If you are looking for a unique case insensitive, then do this.
example "my NamE is John" and "MY naME is jOHN" should match and will not work to have 2,
because if you write "my NamE is John" it will become "My name is john".
and "MY naME is jOHN" will also become "My name is john".
models.py
1. add this code to the top.
capitalizeFirstChar = lambda s: s[:1].upper() + s[1:]
2. Then here is an example how to use it.
class MyModel(models.Model):
name = models.CharField(max_length=255, unique=True)
def __str__(self):
return self.name
# The save method to convert your text "MY naME is jOHN" to "My name is john"
def save(self, force_insert=False, force_update=False):
self.name = self.name.lower()
self.name = capitalizeFirstChar(self.name)
# If the name already exists
if not Category.objects.filter(name__iexact=self.name).exists():
super(Category, self).save(force_insert, force_update)
This solution sucks if you don't want the characters to change in capitalisation.