On 2/7/07, Antonio <[EMAIL PROTECTED]> wrote: > > * mercoledì 07 febbraio 2007, alle 11:27, Russell Keith-Magee wrote : > > > but the data are added also when I update the Previsione ... > > > searching on group archive, I think I must implement a 'save' method > > > into the Previsione class ... is correct ? > > > > I'm not sure I understand what you're trying to do here. The save() > > method on an instance doesn't affect the m2m relations. However, there > > are other mechanisms, such as saving a web form, that will modify m2m > > forms. > > what do you mean with "saving a web form" ?? saving the form and NOT > the save method on instance ?? > > I use : > *** > myform = nf.models.form_for_model(Previsione)(req.POST) > > if myform.is_valid(): > dati = myform.save(commit=False) > ***
Ok - this is saving a form created from a model. Since your model contains a m2m field, the form representing that model will have an m2m widget, and when you save() the form, the m2m relation on the object will be modified. However, if you had an instance of Previsione, and saved it, the m2m fields would not be affected: obj = Previsione(...# some initial data #...) obj.save() # Does not modify m2m data What was confusing me was that it sounded like you wanted to override save() on Previsione (the model), rather than overriding save() on the Previsione form. The former idea won't help; the latter idea will. What you describe in your example looks to be correct - rather than using the save() method on the form for Previsione, you are manually saving the object modified by the form, which allows you to be specific about saving m2m relations, etc. If you were really fancy, you could wrap that logic into a save method on a custom form; this would make your view a little cleaner, but wouldn't affect the way the view operates. Yours, Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---