2
我有喜歡我的我的形式命名的生日字段:Django表單的DateField
class Personal_info_updateForm(forms.Form):
birthdate = forms.DateField(widget=SelectDateWidget(years=[y for y in range(1930,2050)]))
..
..
views.py
def personal_info(request):
mc = MenuCategories()
listCategories = mc.getCategories()
oe = OEConnector()
if request.method == 'POST':
f1 = Personal_info_updateForm(request.POST)
print request.POST
if f1.is_valid():
first_name = f1.cleaned_data['first_name']
last_name = f1.cleaned_data['last_name']
c=[last_name,first_name]
name = " ".join(c)
print name
birthdate = f1.cleaned_data['birthdate']
birthdate_year,birthdate_month,birthdate_day=['','','']
birthdate = [birthdate_year,birthdate_month,birthdate_day]
c=" ".join(birthdate)
print birthdate
title = f1.cleaned_data['title']
print title
email = f1.cleaned_data['email']
mobile = f1.cleaned_data['mobile']
phone = f1.cleaned_data['phone']
result = update_details(name,first_name,last_name,birthdate,email,mobile,phone)
print result
return HttpResponse('/Info?info="Congratulations, you have successfully updated the information with aLOTof"')
a1.html我呼籲全格式如
<form action="" method="POST">
<table style="color:black;text-align:left; margin-left: 20px;">
{{ form.as_table }}
</table>
<input type="submit" value="UPDATE">
</form>
我想要在Postgresql中存儲我的出生日期的值。但它沒有工作,所以我研究了我需要將它轉換爲DateTime字段,因爲日期字段對象是完全不同的。請告訴我如何轉換,以便我可以擺脫此問題。我是把它作爲一個字符串..
在此先感謝