﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13141	ModelForm can't update model like the way it is documented	CNBorn	nobody	"I want to update a model from a modelform,

In a view that handling the POST request, the code is like the following:

{{{
     #If we  already have the object , 'once_set' will be True, this_mapping will be this object

     if request.method == 'POST':
         if once_set == False:
             f = MAPPING_MODEL_Form(request.POST)
             if f.is_valid() == True:
                 f.save()
                 save_success = True
             else:
                 print f.errors
                 save_success = False
         else:   
             f = MAPPING_MODEL_Form(request.POST, instance=this_mapping) 
             if f.is_valid():
                 f.save()
                 save_success = True
             else:
                 print f.errors
                 save_success = False

}}}

It goes well, but when I want to updated a existing model, instead of updating, it always creates a new model with all the new values from request.POST.

I am using Django 1.2 Beta1, I tried with Django 1.1's method (without instance;this_mapping=f.save()) but it didn't work out either.

Therefore I had to turn to this hack:

    {{{this_mapping.update(name=f.cleaned_data['name'], mail=f.cleaned_data['mail'], mobile=f.cleaned_data['mobile'])}}}

Absolutly confirmed with the logic, object do exists and it do creates a new one instead of updating it."		closed	Uncategorized	1.2-beta		worksforme	modelform instance		Unreviewed	0	0	0	0	0	0
