Benedict Verheyen schreef:
> Benedict Verheyen schreef:
>> Hi,
>>
>> i think i might have encountered a possible bug but i'm not sure though.
>> Editing an object and leaving a mandatory field empty results in the
>> form "forgetting" the foreign keys. It doesn't actually forget but it ommits 
>> the
>> "_id" part and thus the values are not displayed on the form.
>> The first time you edit, it works.
>>
>> I encountered it using this scenario:
>> 1. Edit object
>> 2. Delete/blank a mandatory field
>> 3. Save the object
>> 4. You get an error complaining that the field is mandatory
>>    Note that the foreign key fields are now blank
>>
<snip>

I found this comment
(http://www.djangoproject.com/documentation/forms/#using-the-changemanipulator)
This is exactly what happens in my code so this should solve my problem.
Thought i mention it here so other people can benefit from it.

============= Quote ==============
Les October 18, 2006 at 3:35 p.m.

In a Change Manipulator view we should always call
manipulator.do_html2python(new_data) before we check for errors. If
there are errors, FK and M2M field values will not be preserved when the
form reloads with the errors. Only data that is not populated from
external relationships will be maintained

BAD example:
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data) #BAD!!!
manipulator.save(new_data)

# Do a post-after-redirect so that reload works, etc.
return HttpResponseRedirect("/places/edit/%i/" % place.id)

GOOD example:
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
manipulator.do_html2python(new_data) #GOOD!!!
if not errors:
manipulator.save(new_data)

# Do a post-after-redirect so that reload works, etc.
return HttpResponseRedirect("/places/edit/%i/" % place.id)

============= End Quote ==============


Regards,
Benedict


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to