Hello!

I'm starting with django framework; I use django 1.0 and sqlite
database backend.
I've stumbled upon this thing: when editing model entry with ModelForm
I get insert instead of update.

Here's view procedure:
=============================================================================
def edit(request, task_id):
        if request.method == 'POST':
                if task_id  == -1:
                        form = NewTaskForm(data=request.POST, instance=None)
                        if form.is_valid():
                                form.save()
                else:
                        try:
                                task = Task.objects.get(pk=task_id)
                                form = NewTaskForm(data=request.POST, 
instance=task)
                                if form.is_valid():
                                        form.save()
                        except Task.DoesNotExist:
                                raise Http404
                return HttpResponseRedirect(get_test_app_url())
        else:
                if task_id == -1:
                        form = NewTaskForm()
                else:
                        try:
                                task = Task.objects.get(pk=task_id)
                                form = NewTaskForm(instance=task)
                        except Task.DoesNotExist:
                                raise Http404
                return render_to_response('test_app/edit.html', { 'form' : form 
})
=============================================================================

test_app/edit.html looks like this:
=============================================================================
<form action="/py/test_app/edit/" method="POST">
{{ form.as_p }}
        <input type="submit" value="Save" />
</form>
=============================================================================

I guess I miss some obvious thing. Please help to spot it.
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to