kaufen zieht nun geld ab

This commit is contained in:
seba 2011-03-05 00:41:37 +01:00
parent c87580f861
commit fe3502d775
3 changed files with 20 additions and 2 deletions

View File

@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
import datetime
@ -49,13 +50,29 @@ class Order(models.Model):
self.purchase.add(item)
self.price += item.price
def updatePrice(self):
def updatePrice(self, commit=False, updateBalance=False):
self.price = 0.0
for item in self.purchase_set.all():
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):
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):
order = models.ForeignKey(Order)

View File

@ -21,6 +21,7 @@ def showItem(request, itemid):
return HttpResponseRedirect("/buy/")
return render_to_response("buyables/showItem.html", {'item': item}, RequestContext(request))
@login_required
def buyItem(request, itemid, buymode=""):
user = request.user
@ -46,7 +47,7 @@ def buyItem(request, itemid, buymode=""):
p = Purchase.create(order, item, isDeposit=True)
p.order = order
p.save()
order.updatePrice()
order.updatePrice(commit=True)
order.save()
return HttpResponseRedirect("/store/bought/%s/" % (order.id))

Binary file not shown.