django charfield force lowercase 1

django charfield force lowercase

# Just do it in the save method. ie, override the save method of Model class.

def save(self, *args, **kwargs):
    self.username = self.username.lower()
    return super(User, self).save(*args, **kwargs)

Here is what the above code is Doing:
1. It is overriding the save method of the Model class.
2. It is calling the save method of the Model class.
3. It is converting the username to lowercase before saving it.

Similar Posts