I use the decorators:

from django.db import transaction

@transaction.commit_on_success
def create_order(request, customer_id):
    # code to create the form and etc.
    # ...
    order = Order()
    order.customer = get_object_or_404(Customer, pk=customer_id)
    order.save()
    order_note = OrderNote()
    order_note.order = order
    order_note.message = 'Order created by %s.' % request.user.username
    order_note.save()
    # ...

If the order save or the note save fails, neither will be committed


On 3/7/07, johnny <[EMAIL PROTECTED]> wrote:
>
>
> I have to update two models at the same time, if one model update
> fails, I need to rollback the transactions.  How do you do this in
> Django ORM.
>
> Thank you.
>
>
> >
>


-- 
Matt H <[EMAIL PROTECTED]>

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