Malcolm Tredinnick wrote: > I fear you might still be confusing the uses of model.save() and > form.save() here. Mike Keller needed a save() method in his model for > the reasons you noted: he wanted to automatically populate some > particular fields on every save. Regardless of whether the saving is > done via a form or some other method (e.g. a cronjob or a command-line > invocation). > > Independent of whether or not you have a custom save() method for your > models (each model has a default save() method, of course -- it just > saves the currently populated attributes), you will have form.save() in > the case you are considering. The form.save() method for a > from_for_model() result acts as a wrapper that knows how to pull the > data out of the form, put it into the model and call the model's save() > method -- whether it be your custom one or the default one.
Your right. I did not realise they were different. Oh! > The other reason you might not use form.save() is because it is kind of > specific to form_for_model() forms, so it won't always exist. If I can > over-simplify things a little, imagine we split the universe of > Django-created forms into two groups: Group A are those forms which > correspond exactly to one of your model instances (not just one model, > but one instance of that model). For example, a "create object" form in > the admin interface where the input fields correspond precisely to the > model behind it. Group B are those forms where the input data is then > munged in some way and split across possibly multiple models for > storage. An example here might be a form that allows multiple teams for > a competition to be entered -- the data is split across multiple model > instances for saving. > > I find in my own form creation, that I mostly create group B forms, so > form_for_model() doesn't appear in my code very much. Instead, I am > responsible for splitting up the data and populating the right models > and then saving them. > > In short, form.save() is really just a convenience method for one class > of forms where saving is an easy thing to work out how to do. You may > not always have it available. Oh, it's complex. I think I sort of understand the above. Time for me to go back a bit and create some test cases to try out - next week. Thanks Malcolm Have a good weekend to all. -- Michael Lake Computational Research Support Unit Science Faculty, UTS Ph: 9514 2238 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---