-->

TypeError: 'datetime.date' object has no a

2019-02-25 08:42发布

问题:

I use in my models.py

class Pedido(models.Model):
    data_pedido = models.DateField('Data do pedido')
    cliente = models.ForeignKey(Cliente)

but runserver and add date via admin

show this message.

I use sqlite3.

See my project in github

回答1:

Your __unicode__ methods need to return a Unicode string, not a datetime.date object. So you should adapt the following to return Unicode:

def __unicode__(self):
    return self.data_pedido

For example:

def __unicode__(self):
    return unicode(self.data_pedido)

Or you can format the date using a formatting method.