To convert string to lower case replace upper() for lower()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | Show
class Pessoa(models.Model):
nome = models.CharField(max_length=60)
fantasia = models.CharField(max_length=60, blank=True, null=True)
email = models.EmailField("Endereço de E-Mail", unique=True)
class Meta:
abstract = True
def clean_name(self):
return self.cleaned_data["nome"].upper()
Save > override method save
class Pessoa(models.Model):
nome = models.CharField(max_length=60)
fantasia = models.CharField(max_length=60, blank=True, null=True)
email = models.EmailField("Endereço de E-Mail", unique=True)
class Meta:
abstract = True
def save(self, force_insert=False, force_update=False):
self.nome = self.nome.upper()
super(Pessoa, self).save(force_insert, force_update)
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 2 weeks ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 3 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 7 months ago
Comments
You should use srgs and *kwargs when overriding save mthod. so if new parameters are added in the future it doesn't break.
The clean_name function is only used for Form validation AFAIC. Is it valid inside a Model class?
#
#
Please login first before commenting.