TypeError: 'datetime.date' object has no a

2019-02-25 08:48发布

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.

enter image description here

enter image description here

See my project in github

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-02-25 09:46

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.

查看更多
登录 后发表回答