#3260 closed defect (invalid)
inserting date filed value into MySQL
Reported by: | satya sunkara | Owned by: | Adrian Holovaty |
---|---|---|---|
Component: | Core (Other) | Version: | 0.95 |
Severity: | major | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi ,
We are inserting Date field into a MySQL database using a Django form.
Since the form field returns a string representation of Date we are doing the following conversion in our view.
t1=strptime(request.POSTstartdate,"%Y-%m-%d")
t2=strftime("%Y-%m-%d",t1)
and then invoking the model like this
p = project.objects.create(entity_id=e.id,name=request.POSTproject_name,description=request.POSTDescription,startdate=t2,acronym=request.POSTacronym)
We are getting the following error*
AttributeError at /startapp/saveproject/
'str' object has no attribute 'strftime'
Request Method: POST
Request URL: http://127.0.0.1:8000/startapp/saveproject/
Exception Type: AttributeError
Exception Value: 'str' object has no attribute 'strftime'
Exception Location: C:\WorkArea\Python24\lib\site-packages\django-0.95-py2.4.egg\django\db\models\fields\init.py in get_db_prep_save, line 451
After googling around I found that this error is similar to the error in Ticket# 2192
The ticket 2192 was fixed ,but it seems you need to fix the line 449 in fields\init.py
I have temporarily added a following fix at 449 and it worked!!!!
if value is not None and settings.DATABASE_ENGINE != 'mysql':
if value is not None :
value = value.strftime('%Y-%m-%d')
return Field.get_db_prep_save(self, value)
else:
return Field.get_db_prep_save(self, value)
Change History (4)
comment:1 by , 18 years ago
follow-up: 3 comment:2 by , 18 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Can we get a test case to confirm this as an issue?
follow-up: 4 comment:3 by , 18 years ago
Replying to Simon G. <dev@simon.net.nz>:
Can we get a test case to confirm this as an issue?
I don't know what test case you would like to have, but above fix helped me.
comment:4 by , 18 years ago
Replying to lutz@users.sourceforge.net:
Replying to Simon G. <dev@simon.net.nz>:
Can we get a test case to confirm this as an issue?
I don't know what test case you would like to have, but above fix helped me.
A test case is needed so that
- the triage team can easily verify that the bug still exists. For this, multiple reports are probably sufficient
- the developers can find out what's happening and also can easily verify that their fix really solves your problem.
For this, a test case needs to be a step-by-step instruction including all needed models and data, so that when someone else follows them, they will get the same error.
Actually my fix is like this
if value is not None and settings.DATABASE_ENGINE != 'mysql':