well, this is more like it
This commit is contained in:
parent
70a0536de1
commit
35301915be
|
@ -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)
|
||||
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Loading…
Reference in New Issue