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 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to