well, this is more like it

This commit is contained in:
seba 2010-12-02 12:54:34 +01:00
parent 70a0536de1
commit 35301915be
4 changed files with 23 additions and 14 deletions

View File

@ -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)

View File

@ -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 %}

View File

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

Binary file not shown.