You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k4ever/k4ever/buyable/models.py

35 lines
1020 B

from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class BuyableType(models.Model):
name = models.CharField(max_length=100)
def __unicode__(self):
return self.name
class Buyable(models.Model):
name = models.CharField(max_length=100)
price = models.FloatField()
image = models.ImageField(upload_to='img/buyable/')
deposit = models.FloatField()
description = models.TextField()
buyableType = models.ManyToManyField(BuyableType)
def __unicode__(self):
return "%s (%s EUR/%s Pfand)" % (self.name, self.price, self.deposit)
class Purchase(models.Model):
user = models.ForeignKey(User)
dateTime = models.DateTimeField()
price = models.FloatField()
isDeposit = models.BooleanField()
buyable = models.ForeignKey(Buyable)
def __unicode__(self):
return "%s%s, %s by %s" % (self.buyable.name, self.isDeposit and " (deposit)" or "", self.price, self.user)
def create(self, buyable):
self.dateTime = datetime.datetime.now()
self.buyable = buyable