On Apr 22, 11:24 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Tue, 2008-04-22 at 13:47 -0700, Don Spaulding wrote:
>
> [...]
>
> > I try to do something like this:
>
> > order = Order()
> > order.save()
> > order.items.create(price=Decimal("5.00"))
> > order.total         #gives me 0
> > order.save()
> > order.total         #gives me the correct order.total
>
> > My guess is that even though I've saved the item before calling
> > order.save(), the order objects still doesn't know that the new item
> > is related to it.  Anybody know if this is expected behavior?
>
> Yes, it is expected. As Jorge noted, the "order" instance is a snapshot
> of the data at one moment in time, not a live update.
>
Thanks Malcolm and Jorge.  I didn't understand Jorge's response the
first couple times I read it, but now it seems a bit clearer.

I can accept that the item's self.order is stale in Item.save().  But
my use case is still "Every time I add an item to an order, the
order's total needs updated".  How can I force the order to hit the DB
again to find all of its (freshly) related objects?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to