kaufen zieht nun geld ab
This commit is contained in:
parent
c87580f861
commit
fe3502d775
|
@ -1,3 +1,4 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -49,13 +50,29 @@ class Order(models.Model):
|
||||||
self.purchase.add(item)
|
self.purchase.add(item)
|
||||||
self.price += item.price
|
self.price += item.price
|
||||||
|
|
||||||
def updatePrice(self):
|
def updatePrice(self, commit=False, updateBalance=False):
|
||||||
self.price = 0.0
|
self.price = 0.0
|
||||||
for item in self.purchase_set.all():
|
for item in self.purchase_set.all():
|
||||||
self.price += item.price
|
self.price += item.price
|
||||||
|
if commit or updateBalance:
|
||||||
|
# TROLL MODE ON!
|
||||||
|
profile = self.user.get_profile()
|
||||||
|
profile.balance -= self.price
|
||||||
|
profile.save()
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return "Price %s, User %s" % (self.price, self.user)
|
return "Price %s, User %s" % (self.price, self.user)
|
||||||
|
|
||||||
|
#def save(self, *args, **kwargs):
|
||||||
|
#profile = self.user.get_profile()
|
||||||
|
#if self.id == None:
|
||||||
|
## new item, get it!
|
||||||
|
#profile.balance -= self.price
|
||||||
|
#profile.save()
|
||||||
|
#else:
|
||||||
|
## get old
|
||||||
|
#super(Order, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class Purchase(models.Model):
|
class Purchase(models.Model):
|
||||||
order = models.ForeignKey(Order)
|
order = models.ForeignKey(Order)
|
||||||
|
|
|
@ -21,6 +21,7 @@ def showItem(request, itemid):
|
||||||
return HttpResponseRedirect("/buy/")
|
return HttpResponseRedirect("/buy/")
|
||||||
return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request))
|
return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def buyItem(request, itemid, buymode=""):
|
def buyItem(request, itemid, buymode=""):
|
||||||
user = request.user
|
user = request.user
|
||||||
|
@ -46,7 +47,7 @@ def buyItem(request, itemid, buymode=""):
|
||||||
p = Purchase.create(order, item, isDeposit=True)
|
p = Purchase.create(order, item, isDeposit=True)
|
||||||
p.order = order
|
p.order = order
|
||||||
p.save()
|
p.save()
|
||||||
order.updatePrice()
|
order.updatePrice(commit=True)
|
||||||
order.save()
|
order.save()
|
||||||
return HttpResponseRedirect("/store/bought/%s/" % (order.id))
|
return HttpResponseRedirect("/store/bought/%s/" % (order.id))
|
||||||
|
|
||||||
|
|
BIN
k4ever/k4ever.db
BIN
k4ever/k4ever.db
Binary file not shown.
Loading…
Reference in New Issue