formatting error in a field models.DateField()

116 Views Asked by At

I have a model in the models.py file of my django project, where a date field does not respect the format in the admin, where it appears as if it were a charField.

from django.db import models

class registro(models.Model): fechaNacimiento = models.DateField()

enter image description here

1

There are 1 best solutions below

2
Gustavo Henrique Zollner Munho On

I don't know if I understood you, but I think you want something like that in the model too, to format like in admin

from django.db import models

class Registro(models.Model):
    fechaNacimiento = models.DateField()

    def fecha_formateada(self):
        return self.fechaNacimiento.strftime('%d/%m/%y')