newrugs = models.DateField(auto_now_add=True)
Now, when I try to view my Style objects in the admin I get the
following error:
AttributeError at /admin/plush/style/5/
'unicode' object has no attribute 'strftime'
////////////////////
Any suggestions on what's causing this?
In c:\Python24\lib\site-packages\django\db\models\fields\__init__.py
and changed the method 'flatten_data(self, follow, obj=None):'. I
changed the following line of code from:
return {self.attname: (val is not None and val.strftime("%Y-%m-%d") or
'')}
to
return {self.attname: (val is not None or '')}
/////////
That seems to fix the problem. Is the code that I took needed there
for a reason? Will this changed have an effect on how other areas of
my application work?
Thanks
>That seems to fix the problem. Is the code that I took needed there
>for a reason? Will this changed have an effect on how other areas of
>my application work?
Yes, that code is needed and is there for a reason. The object
passed to that function should NOT be a unicode object, it ought to
be a datetime object so that strftime can be called on it to properly
format it. The bug is not the line of code you changed, it is
whatever is causing a unicode object to be passed into the
flatten_data function.
I see from the archives you have brought this problem to the group
before, but I don't see any resolution. I gather you are using
sqlite, which, I'm sorry, I know nothing about so I can't really help
you. For some reason you are getting back a unicode object from the
db instead of a datetime. You say you just added this DateTime field
to your model. Did you modify the table in sqlite yourself or did
you re-initialize using django? It seems that either your version of
sqlite is behaving oddly and returning a unicode string for something
that ought to be a datetime object, or the field is not of the proper
type in the database.
Karen