From 35301915beff8065fdcc52ab7b81741ef46911b5 Mon Sep 17 00:00:00 2001 From: seba Date: Thu, 2 Dec 2010 12:54:34 +0100 Subject: [PATCH] well, this is more like it --- k4ever/buyable/models.py | 14 +++++++++++- .../templates/buyables/itemBought.html | 2 +- k4ever/buyable/views.py | 21 ++++++++---------- k4ever/k4ever.db | Bin 65536 -> 62464 bytes 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/k4ever/buyable/models.py b/k4ever/buyable/models.py index 9253d84..aba9d77 100644 --- a/k4ever/buyable/models.py +++ b/k4ever/buyable/models.py @@ -34,7 +34,6 @@ class Buyable(models.Model): class Order(models.Model): user = models.ForeignKey(User) - purchase = models.ManyToManyField('Purchase') price = models.FloatField() dateTime = models.DateTimeField() @@ -54,10 +53,23 @@ class Order(models.Model): return "Price %s, User %s" % (self.price, self.user) class Purchase(models.Model): + order = models.ForeignKey(Order) price = models.FloatField() isDeposit = models.BooleanField() buyable = models.ForeignKey(Buyable) + def create(order, buyable): + p = Purchase() + p.order = order + if isDeposit: + p.price = self.deposit + else: + p.price = self.price + p.dateTime = datetime.datetime.now() + p.buyable = buyable + + return p + def __unicode__(self): return "%s%s, %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price) diff --git a/k4ever/buyable/templates/buyables/itemBought.html b/k4ever/buyable/templates/buyables/itemBought.html index f95f68f..280b0e9 100644 --- a/k4ever/buyable/templates/buyables/itemBought.html +++ b/k4ever/buyable/templates/buyables/itemBought.html @@ -3,7 +3,7 @@ {% block "content" %} {% if not error %} You got the order {{ order }} - {% for item in order.purchase.all %} + {% for item in order.purchase_set.all %} {{ item }} {% endfor %} {% else %} diff --git a/k4ever/buyable/views.py b/k4ever/buyable/views.py index eb36ea4..753a293 100644 --- a/k4ever/buyable/views.py +++ b/k4ever/buyable/views.py @@ -34,21 +34,18 @@ def buyItem(request, itemid, buymode=""): "with/deposit" item and deposit "only/deposit" only deposit """ - items = [] - if buymode == "" or buymode == "with/deposit": - p = item.createPurchase(isDeposit=False) - p.save() - items.append(p) - # TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit": - if buymode == "with/deposit" or buymode == "only/deposit": - p = item.createPurchase(isDeposit=True) - p.save() - items.append(p) order = Order() order.resetWithUser(user) order.save() # for the id! - order.addItems(items) - order.save() + if buymode == "" or buymode == "with/deposit": + p = item.createPurchase(isDeposit=False) + p.order = order + p.save() + # TANNEK! if buymode == "with/dopsit" or buymode == "only/deposit": + if buymode == "with/deposit" or buymode == "only/deposit": + p = item.createPurchase(isDeposit=True) + p.order = order + p.save() return HttpResponseRedirect("/store/bought/%s/" % (order.id)) @login_required diff --git a/k4ever/k4ever.db b/k4ever/k4ever.db index 59f1e3bc808c9b9df86c273cc6e69ffce5737d82..15e28873764e81671decd8505b19068a6f5a215b 100644 GIT binary patch delta 1626 zcmai!ZERCz6vv-)&+Xa`rmMi(z0r1C_ul5d_TEA4GBXMMS{?79npOun1~5R7{nk%KZuDlp_>V42qwm-?dC8@eA0W;`@83! z=YP&~&W*>#_zdo^vJW%H+WEDx>JPN3FnngyE?m*VnZJP>ubUfpH8)jGx`i%m#6Q#a zrE_R!4Nie$z?rzCOqERU-N8}&?a4h*`#V09lSqdpqNR|8nRW=OufhUUW*A>&yf+7LrliS=95w^dXs@DE&$>+2;&!Gc z2aFQD!IR1`%-{_k^8_~6V>kR?q+BVyWEVZD^`ck=c$;Bf5jvItvYMx3!$apk+SXs1 zuh?CNcX<(K@v$Nh8BZQc{>|yPS1ijo&bfl*-}&q2=q2B@Kq z{&OYCkkjh$`QV*KO2xgflEZSEjhnP-YbC90DP0oT`C2$K5ZkzYC`yz4ZPb|vmlUKN zV|a{bc^Hdd0xMf#9klxB#P&7r?(lHTJ(x3*fiPcrB{d#q0PLj^j}-@?G3yw-hn30*D=7AI`1!8Q8@IbW_bQjqD1mBix=)!0l)Te(R-2=Rt z-aMp23!Ogn940DU)HmJe=TcMtIPwF7k?1YmuRoLdGH!ih-LLXmR4GnbbQWvNc&X&J7y__PKg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