﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3260	inserting date filed value into MySQL	satya sunkara	Adrian Holovaty	"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.POST['startdate'],""%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.POST['project_name'],description=request.POST['Description'],startdate=t2,acronym=request.POST['acronym'])	

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)
"	defect	closed	Core (Other)	0.95	major	invalid			Unreviewed	0	0	0	0	0	0
