TypeError:'datetime.date'对象没有属性'__getitem__' [英] TypeError: 'datetime.date' object has no attribute '__getitem__'
本文介绍了TypeError:'datetime.date'对象没有属性'__getitem__'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的models.py中使用
I use in my models.py
class Pedido(models.Model):
data_pedido = models.DateField('Data do pedido')
cliente = models.ForeignKey(Cliente)
runserver并通过管理员添加日期
but runserver and add date via admin
显示此消息。
我使用sqlite3。
I use sqlite3.
我的项目在 github
推荐答案
您的 __ unicode __
方法需要返回一个Unicode字符串,而不是一个 datetime.date
对象。所以你应该调整以下内容来返回Unicode:
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
例如:
def __unicode__(self):
return unicode(self.data_pedido)
或者您可以使用格式化方法格式化日期。
Or you can format the date using a formatting method.
这篇关于TypeError:'datetime.date'对象没有属性'__getitem__'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文