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





     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
-~----------~----~----~----~------~----~------~--~---

Reply via email to