>def add_edit_model(request, id=None):
> if id is not None:
> instance = MyModel.objects.get(id=id)
> InstanceForm = MyForm(instance=instance)
> else:
> InstanceForm = MyForm()
> if request.POST:
> form = InstanceForm(request.POST)
> if form.is_valid():
> form.save()
> return HttpResponseRedirect('/whatever/url/')
> return render_to_response('template.html', {'form': InstanceForm})
I looked at this previous posting that showed the proper way to
construct add/edit newForms. I got most of it working, but I am
having trouble saving the edit form.
The line of code "form = InstanceForm(request.POST)" doesn't make
any sense. The InstanceForm was already created so how can you pass
POST information to it again? When I use this method I keep adding
new items when I really only want to update a current item. Is there
some other way to pass the POST information to an instance form which
is already created?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---