Mr.Huang
Mr.Huang

Reputation: 55

an error with models.DateField()

I write a django app,but there is error troubling me. this is the code from my model:

class Orders(models.Model):
    checkin = models.DateField()
    checkout = models.DateField()
    total  = models.FloatField()
    client = models.ForeignKey(Client)
    def __unicode__(self):
        return self.checkin

last, I add a record with Django administration,and submit, it return an error: http://dpaste.com/1202450/ thanks.

Upvotes: 1

Views: 62

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599490

Your __unicode__ method must return a unicode string, not a date. You should convert the field:

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

You may want to convert the date to a specific human-readable format instead, using strftime.

Upvotes: 3

Related Questions