I'm not sure if this is a bug or just my own misunderstanding, but I've
been having problems getting manipulators to work right with models
that have foreign keys. When I save the manipulator, it duplicates the
existing foreign key objects.
As an example, using the poll model in the Django tutorial, if I have a
poll object with two choices, "Shaft" and "Superfly" and then I save
the manipulator for it without altering the existing choices, I then
end up with four choices, "Shaft" twice and "Superfly" twice. If I
modify an existing choice (say, I change "Shaft" to "Dolomite"), I end
up with the unmodified choices and the modified choice ("Shaft",
"Superfly" twice and "Dolomite"). My view looks like this:
from myproject.test.models import Poll, Choice
from django import forms
from django.shortcuts import render_to_response
from django.http import HttpResponse
def edit( request, poll_id):
manipulator = Poll.ChangeManipulator( poll_id )
if request.POST:
new_data = request.POST.copy()
errors = manipulator.get_validation_errors( new_data )
if not errors:
manipulator.do_html2python( new_data )
manipulator.save( new_data )
return HttpResponse("thank you.")
else:
new_data = manipulator.flatten_data()
form = forms.FormWrapper( manipulator, new_data, {} )
return render_to_response( 'test/edit_form.html', { 'form' :
form } )
My edit_form.html template looks like:
<html>
<body>
<form method = "post" action=".">
Question: {{ form.question }}
<h2>Choices</h2>
{% for choiceOn in form.choice %}
{{ choiceOn.choice }} {{choiceOn.votes}} <br />
{% endfor %}
<input type="submit">
</form>
</body>
</html>
I'm using the latest code from SVN. Thanks.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---