ok I've added instance=object! is it ok, that when I change PK value and call form.save() it create new item, and not just update PK value on already existen item if PK is _not_ AutoField? if it is ok, then how to change value of PK field if it is not AutoField? :)
if request.method == 'POST': new_data = request.POST.copy() # now pass instance kw form = model_form(new_data, instance=object) if form.is_valid(): new_object = form.save() response = model_post_save(new_object) return response else: form = model_form(instance=object) On Apr 24, 1:33 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2008-04-24 at 03:03 -0700, sector119 wrote: > > Why this code allways create new objects and never update them!? How > > to update objetcs, not create them using form.save() > > > Model PK is AutoField. When it not autoincrement field everything > > works fine! > > At no point in your code are you giving it any information about what > existing model instance you would want to be updated. If you want an > existing instance to be updated, you must pass it in when you create the > form instance (you do this in the non-POST path, but not in the POST > path). > > Regards, > Malcolm > > -- > Everything is _not_ based on faith... take my word for > it.http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---