Am Freitag, 26. Oktober 2007 10:53 schrieb äL:
> I use Django to manage addresses. To publish the data I have a list
> and a detailed view. In the detail view I can change the name,
> address, phone, etc. of the person. To do that I created an edit
> form.
>
> Now, everythin is fine. Only if I try to change and save the birthday
> (witch is a datefield) it doesn't work. Everthing else is no problem.
> Does anybody know why I cannot save datefields?
What mean "doesn't work"? Nothings happens? Do you get a traceback?
[cut]
> ## views.py ##
> def Karateka_save(request, karateka_id):
> from kav.info.models import Karateka, Country, Location, Dojo
> karateka = Karateka.objects.get(id = karateka_id)
>
> try:
> karateka.person.nameLast = request['nameLast']
> karateka.person.nameFirst = request['nameFirst']
> karateka.person.address = request['address']
> karateka.person.phone = request['phone']
> karateka.person.birthdate = request['birthdate']
> karateka.comment = request['comment']
>
> karateka.save()
> karateka.person.save()
> except:
> return HttpResponseRedirect("/info/karateka-%d/edit" %
> int(karateka_id))
>
> return HttpResponseRedirect("/info/karateka-%d/" %
> int(karateka_id) )
> ## end views.py ##
this looks very strange. I guess you are new to python programming.
Some hints:
- don't catch all exceptions ("except:")
- keep only few (at best one line) between "try" and "except".
- birthday is of type datetime.date. You set it to a string.
- Have a look at newforms. form_for_model and form_for_instance
might help you. You should use forms.DateField for the birthday.
Thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---