its working now but i dont like the relationship

order shouldn't have to know about his purchases
purchases should know their order!
purchases would be accessible by calling
       order.purchase_set()
This commit is contained in:
seba 2010-12-02 10:35:02 +01:00
parent 4f37807ef1
commit 70a0536de1
2 changed files with 2 additions and 1 deletions

View File

@ -48,6 +48,7 @@ class Order(models.Model):
def addItems(self, items): def addItems(self, items):
for item in items: for item in items:
self.purchase.add(item) self.purchase.add(item)
self.price += item.price
def __unicode__(self): def __unicode__(self):
return "Price %s, User %s" % (self.price, self.user) return "Price %s, User %s" % (self.price, self.user)
@ -58,7 +59,7 @@ class Purchase(models.Model):
buyable = models.ForeignKey(Buyable) buyable = models.ForeignKey(Buyable)
def __unicode__(self): def __unicode__(self):
return "%s%s, %s by %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price, self.user) return "%s%s, %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price)
# def save(self, *args, **kwargs): # def save(self, *args, **kwargs):
# profile = self.user.get_profile() # profile = self.user.get_profile()

Binary file not shown.