The downside to putting it in the form is that the form should only be used for presentation. Putting this logic in the form is pushing programatic decisions to the presentation layer.
I believe the better approach is defining a view method that can be shared by multiple urls. ________________________________ From: [email protected] To: [email protected] Sent: Mon Feb 02 15:16:07 2009 Subject: Re: Autogenerate a Model on Save the view is the first, and most easily understandable place to put it. the form logic may make your head hurt more at first, but eventually you'll feel more comfortable putting it there. nothing wrong with coding it in the view but OTOH you will get the same functionality if you use the form in your own view or in the admin. and if you create more views for different purposes, they can all use that form. On Mon, Feb 2, 2009 at 9:09 PM, Will Matos <[email protected]> wrote: Agreed. Your class is being saved in a view method. Upon successful saves create a new one. ________________________________ From: [email protected] To: [email protected] Sent: Mon Feb 02 15:07:48 2009 Subject: Re: Autogenerate a Model on Save generally you should keep this type of business logic out of the model the place to put it is either in the Form or the view class OrderModelForm(forms.ModelForm): class Meta: model = Order def save_model(self, request, obj, form, change): """ Given a model instance save it to the database. """ if not change: # only when adding obj.created_by = request.user if(not obj.from_email): obj.from_email = request.user.email #create your invoice now obj.save() # and if you are using that in the admin then add it to the admin too: class OrderAdmin(admin.ModelAdmin): form = OrderModelForm and register it <http://crucial-systems.com/crucialwww/imgs/tartan46.gif> felix : crucial-systems.com On Mon, Feb 2, 2009 at 8:50 PM, Alfonso <[email protected]> wrote: I'm full of queries today!...This one seems a simple notion that I can't get my head around...How would I get django to auto-generate a new Invoice record and populate with some values when a user saves a new Order record? A custom def save(self) method? Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---

