Login

Convert String Uppercase and Lowercase

Author:
oraculum
Posted:
April 15, 2011
Language:
Python
Version:
1.2
Tags:
string uppercase lowercase
Score:
0 (after 2 ratings)

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

  1. Filter; Capitalise Sentences (capsentence) by djm 6 years, 3 months ago
  2. SAS70 Compliant Password Validator by czieler 7 years, 9 months ago
  3. Convert CamelCase to lowercase_with_underscores by jdriscoll 7 years, 3 months ago
  4. Greek uppercase tag for django by petkostas 1 year, 4 months ago
  5. Roman Numeral Filter by Paperface 8 years, 1 month ago

Comments

dudus (on April 15, 2011):

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?

#

dudus (on April 15, 2011):
  • Fix: You should use *args and **kwargs

#

Please login first before commenting.