I'm not getting __repr__ right.
Trying to add a period in the admin side:
TypeError at /admin/timekeeper/period/add/
__str__ returned non-string (type datetime.date)Request Method: POST
Request URL: http://localhost:8000/admin/timekeeper/period/add/
Exception Type: TypeError
Exception Value: __str__ returned non-string (type datetime.date)
Exception Location: c:\python25\lib\site-packages\django\contrib\admin\views\main.py
in add_stage, line 256
The model:
class Period(models.Model):
end_date = models.DateField('end date')
insert_date = models.DateTimeField('date inserted', auto_now_add=True)
def __str__(self):
return self.end_date
class Admin:
pass
Is there an easy way to munge the return self.end_date into a string?
Thanks for the help.
--
Andrew Diederich
This is a Python requirement -- __str__() methods must return a
string. To fix the problem, wrap self.end_date in str(), like so:
return str(self.end_date)
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.com
Perfect. I thought it would be intensely easy. Thanks for the help.
--
Andrew Diederich