thanks for your answer. That's what I'm doing now. Unfortunately, I don't have time to dive deeper into CustomManipulators but maybe for the next project.
Best regards
chris
On 5/26/06, Jorge Gajon <[EMAIL PROTECTED]> wrote:
Hi,
I also found that behavior and what I did was to copy
new_data['station'] to new_data['station_id'] when there were errors
from "get_validation_errors()". Like this:
def change_recording(request, recording_id):
....snip.....
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors(new_data)
if not errors:
manipulator.do_html2python(new_data)
new_recording = manipulator.save(new_data)
return HttpResponseRedirect("/dwasrod/")
else:
new_data['station_id'] = new_data['station']
new_data['other_foreign_id'] = new_data['other_foreign']
else:
new_data = recording.__dict__
....snip....
I later had to create a custom manipulator instead of using the
default one. With a custom manipulator you don't have this field name
discrepancy, and don't need to do that value copying. I now prefer to
use a custom manipulator.
Cheers,
Jorge
On 5/25/06, Christian Schneider < [EMAIL PROTECTED]> wrote:
> Hi all,
>
> I've written (well copied) the following view. In my model I have a defined
> an attribute "station = models.ForeignKey(Station)". Now, if I call the
> change view, the station is selected. However, if I submit the change view
> with some errors, the station is de-selected in the new view.
>
> I've also written a create view that is given a station id on creation an
> pre-populates the interface. Here I found that the foreign key's id comes in
> as new_data["station"] but has to go out as new_data["station_id"]. Is that
> correct and do the generic views stuff like that under the hood?
>
> Form fields for many-to-many relations work as expected, so maybe I'm doing
> something wrong with the foreign key fields.
>
> Any hints are - as always - welcome
>
> chris
>
>
> def change_recording(request, recording_id):
> try:
> manipulator = Recording.ChangeManipulator(recording_id)
> except:
> raise Http404
>
> recording = manipulator.original_object
>
> errors = {}
> new_data = {}
>
> if request.POST:
> new_data = request.POST.copy()
> errors =
> manipulator.get_validation_errors (new_data)
> if not errors:
> manipulator.do_html2python(new_data)
> new_recording = manipulator.save(new_data)
> return HttpResponseRedirect("/dwasrod/")
> else:
> new_data = recording.__dict__
>
> form = FormWrapper(manipulator, new_data, errors)
> return
> render_to_response('aufnahmen/recording_form.html',
> {'form': form})
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

