Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'datetime.date' object has no attribute '__getitem__'

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

like image 625
Regis Santos Avatar asked Jan 28 '26 23:01

Regis Santos


1 Answers

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.

like image 179
Simeon Visser Avatar answered Jan 30 '26 16:01

Simeon Visser



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!