Editing tables, DateField field

1

In one of the insert's of my application, I have a DateField field, At first there is no error when saving the dates in the database ( SQLite3 ), I I report a date in the format DD/MM/AAAA , and it is saved in the format AAAA/MM/DD in the database.

When editing some database table, the fields are already filled with the information already saved with the exception of the date field, in Firefox it is filled in the format: "July 11, 2014", already in Chrome the date field is not filled with the date I want to edit.

models.py:

class Pessoa(models.Model):

    codigo = models.CharField('Codigo', max_length = 10)
    nome = models.CharField('Nome', max_length = 100)
    d_nasc = models.DateField('Data de Nascimento')
    cpf = models.CharField('CPF',max_length = 14)
    telefone = models.CharField('Telefone',max_length = 12)
    endereco = models.CharField('Endereço',max_length = 200)
    email = models.EmailField('E-mail',max_length = 75)
    tipo = models.CharField('Tipo',max_length = 100)

    biblioteca = models.ForeignKey(Biblioteca, blank=True, null=False)

    def __unicode__(self):
        return self.nome

forms.py

class FormPessoa (forms.ModelForm):

    class Meta:
        model = Pessoa

views.py

@login_required
def upPessoa(request, id):

    oPessoa = Pessoa.objects.get(pk=id)
    if request.method == 'POST':
        form = FormPessoa(request.POST, instance=oPessoa)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('nPesqUsuario'))
    else:
        form = FormPessoa(instance=oPessoa)

    return render(request,'edicao_usuario.html',
                {
                    'form':form,
                    'codigo':id,
                }
            )

How do I edit the date field when the tables are already filled in with the date saved in the Bank in the format DD/MM/AAAA ?

I do not want to have to save all fields with the field CharField !

The complete project is in GitHub .

    
asked by anonymous 14.07.2014 / 03:43

1 answer

2

In Django 1.7 the Brazilian format is automatically identified, at least that's what's happening to me. In Django 1.6 I would add the date format, eg:

data_de_nascimento = forms.DateField(
    label=_(u'Data de Nascimento:'), 
    input_formats=["%d/%m/%Y",], 
    widget=forms.DateInput(format='%d/%m/%Y')
)

In the database the saved format will be the default Y-m-d , but in the template / forms Django will present the format you define.

    
14.07.2014 / 05:22