Search code examples
pythondjangomodeladmindatefield

formatting error in a field models.DateField()


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


Solution

  • 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')