problem with uppercase in Django

Asked

Viewed 323 times

0

I have an uppercase problem in Jango, in the following code, it works in the first form (name) and in the last form (organ), but in the intermediary forms it does not turn the letters sent in the bank into uppercase...

py.models

class Requerente(models.Model):
NACIONALIDADE = (
    ('BRASILEIRO', 'BRASILEIRO'),
    ('BRASILEIRA', 'BRASILEIRA'),
    ('ESTRANGEIRO', 'ESTRANGEIRO'),
    ('ESTRANGEIRA', 'ESTRANGEIRA'),
    )
ESTADO_CIVIL = (
    ('CASADO', 'CASADO'),
    ('CASADA', 'CASADA'),
    ('SOLTEIRO', 'SOLTEIRO'),
    ('SOLTEIRA', 'SOLTEIRA'),
    ('DIVORCIADO', 'DIVORCIADO'),
    ('DIVORCIADA', 'DIVORCIADA'),
    ('VIÚVO', 'VIÚVO'),
    ('VIÚVA', 'VIÚVA'),
)
REGIME = (
    ('COMUNHAO DE BENS', 'COMUNHAO DE BENS'),
    ('COMUNHAO PARCIAL DE BENS', 'COMUNHAO PARCIAL DE BENS'),
    ('SEPARAÇÃO DE BENS', 'SEPARACAO DE BENS'),
    )
nome = models.CharField(max_length=100)
nacionalidade = models.CharField(choices=NACIONALIDADE, max_length=50, null=True)
estado_civil = models.CharField(u'estado civil', max_length=50, choices=ESTADO_CIVIL, null=True)
nubente = models.CharField(max_length=100, null=True)
regime = models.CharField(u'regime', max_length=50, choices=REGIME, blank=True, null=True)
profissao = models.CharField(max_length=50, null=True)
rg = models.CharField(max_length=100, null=True)
orgao = models.CharField(max_length=50, null=True)
cpf = models.CharField(max_length=14, )
logradouro = models.ForeignKey(Logradouro, verbose_name=u'Rua, Av.')
numero = models.CharField(max_length=50, )
bairro = models.ForeignKey(Bairro, )
cidade = models.ForeignKey(Cidade)
telefone = models.CharField(max_length=20, blank=True, null=True)
celular =  models.CharField(max_length=20, blank=True, null=True)

def __unicode__(self):
    return self.nome
def save(self, force_insert=False, force_update=False):
    self.nome = self.nome.upper()
    super(Requerente, self).save(force_insert, force_update)

def save(self, force_insert=False, force_update=False):
    self.nubente = self.nubente.upper()
    super(Requerente, self).save(force_insert, force_update)

def save(self, force_insert=False, force_update=False):
    self.profissao = self.profissao.upper()
    super(Requerente, self).save(force_insert, force_update)

def save(self, force_insert=False, force_update=False):
    self.orgao = self.orgao.upper()
    super(Requerente, self).save(force_insert, force_update)

2 answers

1


Why don’t you try using just one save and go treating these Fields in that save?

Here’s a possible solution, using a single save to treat Fields:

def save(self, *args, **kwargs):
    self.nubente = self.nubente.upper()
    self.profissao = self.profissao.upper()
    self.orgao = self.orgao.upper()

    super(Requerente,self).save(*args,**kwargs)

Put this single save on your Model and try to run again.

  • Thank you very much !!!

  • @Lucasjunior Show!! Glad it worked out. Mark the answer as the correct one in case someone else has the same question.

0

If you wanted to, you can also use the clean function in models.py so you don’t have to overwrite the save function.

    class Requerente(models.Model):

        nacionalidade = models.CharField(choices=NACIONALIDADE, max_length=50, null=True)

        def clean(self):
            self.nacionalidade = str(self.nacionalidade.upper())

So the bank recording and recovery will always be capitalized.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.