-
Christian Dresen authoredChristian Dresen authored
models.py 1.99 KiB
from __future__ import unicode_literals
from django.db import models
from rest_framework import routers, serializers, viewsets
from warpauth.models import LdapUser
class ProductCategory(models.Model):
name = models.CharField(max_length=100, unique=True)
def __str__(self):
return self.name
class ProductCategorySerializer(serializers.ModelSerializer):
class Meta:
model = ProductCategory
fields = ['id', 'name']
class Product(models.Model):
name = models.CharField(max_length=100, null=True)
price_ek = models.FloatField()
price_vk = models.FloatField()
category = models.ForeignKey(ProductCategory, on_delete=models.CASCADE, null=True)
stock_count = models.IntegerField()
barcode = models.CharField(max_length=100, null=True)
def __str__(self):
return self.name
class ProductSerializer(serializers.ModelSerializer):
category = serializers.StringRelatedField()
class Meta:
model = Product
fields = ['id', 'name', 'price_vk', 'category', 'barcode','stock_count']
class Transaction(models.Model):
date = models.DateTimeField(auto_now_add=True)
product = models.ForeignKey(Product, on_delete=models.CASCADE, null=True)
type = models.IntegerField() # 1: aufladen; 2:kaufen
amount = models.FloatField()
cash_paid = models.BooleanField(default=False)
def __str__(self):
return str(self.amount) #self.product.name+" - "+self.amount
class TransactionLog(models.Model):
uid = models.CharField(max_length=100)
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE, null=True)
class UserCredit(models.Model):
uid = models.CharField(max_length=100,unique=True)
card_id = models.CharField(max_length=10, null=True) # Unique only with django 1.11
credit = models.FloatField()
def __str__(self):
return self.uid
class UserCreditSerializer(serializers.ModelSerializer):
class Meta:
model = UserCredit
fields = ['uid', 'card_id', 'credit']