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):
|
class Order(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
purchase = models.ManyToManyField('Purchase')
|
|
||||||
price = models.FloatField()
|
price = models.FloatField()
|
||||||
dateTime = models.DateTimeField()
|
dateTime = models.DateTimeField()
|
||||||
|
|
||||||
|
@ -54,10 +53,23 @@ class Order(models.Model):
|
||||||
return "Price %s, User %s" % (self.price, self.user)
|
return "Price %s, User %s" % (self.price, self.user)
|
||||||
|
|
||||||
class Purchase(models.Model):
|
class Purchase(models.Model):
|
||||||
|
order = models.ForeignKey(Order)
|
||||||
price = models.FloatField()
|
price = models.FloatField()
|
||||||
isDeposit = models.BooleanField()
|
isDeposit = models.BooleanField()
|
||||||
buyable = models.ForeignKey(Buyable)
|
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):
|
def __unicode__(self):
|
||||||
return "%s%s, %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price)
|
return "%s%s, %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price)
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% block "content" %}
|
{% block "content" %}
|
||||||
{% if not error %}
|
{% if not error %}
|
||||||
You got the order {{ order }}
|
You got the order {{ order }}
|
||||||
{% for item in order.purchase.all %}
|
{% for item in order.purchase_set.all %}
|
||||||
{{ item }}
|
{{ item }}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -34,21 +34,18 @@ def buyItem(request, itemid, buymode=""):
|
||||||
"with/deposit" item and deposit
|
"with/deposit" item and deposit
|
||||||
"only/deposit" only 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 = Order()
|
||||||
order.resetWithUser(user)
|
order.resetWithUser(user)
|
||||||
order.save() # for the id!
|
order.save() # for the id!
|
||||||
order.addItems(items)
|
if buymode == "" or buymode == "with/deposit":
|
||||||
order.save()
|
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))
|
return HttpResponseRedirect("/store/bought/%s/" % (order.id))
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Loading…
Reference in New Issue