BuyAndKnow/bk_api/bills/models.py
Stanislaw-Golebiewski 527d60c70c backend setup
2020-01-05 21:41:14 +01:00

67 lines
2.5 KiB
Python

from django.db import models
from django.contrib.auth.models import User
class Tag(models.Model):
name = models.CharField(max_length=30)
color = models.CharField(max_length=30, default="#f2f2f2")
created_at = models.DateField(auto_now_add=True)
owner = models.ForeignKey(User, related_name="tags", on_delete=models.CASCADE, null=True)
def __str__(self):
return f"{self.name} | {self.owner.username}"
class ShopTag(models.Model):
name = models.CharField(max_length=30)
color = models.CharField(max_length=30, default="#9e9e9e")
created_at = models.DateField(auto_now_add=True)
owner = models.ForeignKey(User, related_name="shop_tags", on_delete=models.CASCADE, null=True)
def __str__(self):
return f"{self.name} | {self.owner.username}"
class Shop(models.Model):
name = models.CharField(max_length=30)
created_at = models.DateField(auto_now_add=True)
tags = models.ManyToManyField(ShopTag, blank=True)
owner = models.ForeignKey(User, related_name="shops", on_delete=models.CASCADE, null=True)
def __str__(self):
return f"{self.name} | {self.owner.username}"
class Product(models.Model):
name = models.CharField(max_length=30)
created_at = models.DateField(auto_now_add=True)
owner = models.ForeignKey(User, related_name="products", on_delete=models.CASCADE, null=True)
default_tags = models.ManyToManyField(Tag, blank=True)
def __str__(self):
return f"{self.name} | {self.owner.username}"
class Receipt(models.Model):
shop = models.ForeignKey(Shop, related_name="receipts", on_delete=models.CASCADE, blank=True)
created_at = models.DateField(auto_now_add=True)
date = models.DateField(auto_now_add=False)
owner = models.ForeignKey(User, related_name="receipts", on_delete=models.CASCADE, null=True)
total_price = models.FloatField(default=float(0.00))
def __str__(self):
return f"{self.shop} | {self.total_price} zł | {self.owner.username}"
class ProductOnBill(models.Model):
name = models.CharField(max_length=30)
created_at = models.DateField(auto_now_add=True)
price = models.DecimalField(max_digits=5, decimal_places=2)
receipt = models.ForeignKey(Receipt, related_name="products", on_delete=models.CASCADE)
tags = models.ManyToManyField(Tag, blank=True)
owner = models.ForeignKey(User, related_name="products_on_bills", on_delete=models.CASCADE, null=True)
def __str__(self):
return f"{self.name} | {self.price} zł | {self.owner.username}"