I think I must have fallen through the cracks of "nobody will ever
want to do *this*" when building this app.  Given the following two
models (simplified for clarity):

class Order(models.Model):
    total = models.DecimalField(...)

    def save(self):
        tmp_total = Decimal()
        for item in self.items.all():
            tmp_total += item.price
        self.total = tmp_total
        super(Order, self).save()

class Item(models.Model):
    order = models.ForeignKey(Order, related_name='items')
    price = models.DecimalField(...)

    def save(self):
        super(Item, self).save()
        self.order.save()

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?

Thanks,
Don
--~--~---------~--~----~------------~-------~--~----~
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