from ctypes import DEFAULT_MODE
from django.db import models
from django.db.models.deletion import CASCADE, PROTECT
from django.db.models.expressions import Col
from django.db.models.fields import PositiveSmallIntegerField
from django.utils.translation import pgettext_lazy
class Promotions(models.Model):
description = models.CharField(max_length=255)
discount = models.FloatField()
class Collection(models.Model):
title = models.CharField(max_length=255)
class Product(models.Model):
title = models.CharField(max_length=255)
descriptions = models.TextField()
price = models.DecimalField(max_digits=5, decimal_places=2)
inventory = models.IntegerField()
last_update = models.DateTimeField(auto_now=True)
collection = models.ForeignKey(Collection, on_delete=models.PROTECT)
promotion = models.ManyToManyField(Promotions, on_delete=models.CASCADE)
class Customer(models.Model):
MEMBERSHIP_BRONZE = "B",
MEMBERSHIP_SILEVR = "S",
MEMBERSHIP_GOLD = "G"
MEMBERSHIP_CHOICES = [
('B', 'Bronze'),
('S', 'Silver'),
('G', 'Gold')
]
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.EmailField(unique=True)
phone = models.CharField(max_length=255)
birth_date = models.DateField(null=True)
membership = models.CharField(
max_length=1, choices=MEMBERSHIP_CHOICES, default=MEMBERSHIP_BRONZE)
class Order(models.Model):
PAYMENT_STATUS_PENDING = "P"
PAYMENT_STATUS_COMPLETE = "C"
PAYMENT_STATUS_FAILED = "F"
PEYMENT_STATUS_CHOICES = [
(PAYMENT_STATUS_PENDING, "Pending"),
(PAYMENT_STATUS_COMPLETE, "Complete"),
(PAYMENT_STATUS_FAILED, "Failed")
]
placed_at = models.DateTimeField(auto_now_add=True)
payment_status = models.CharField(
max_length=1, choices=PEYMENT_STATUS_CHOICES, default=PAYMENT_STATUS_PENDING)
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
class Address(models.Model):
street = models.CharField(max_length=255)
city = models.CharField(max_length=255)
customer = models.ForeignKey(Customer, on_delete=models.CASCADE)
class Cart(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
class OrderItem(models.Model):
order = models.ForeignKey(Order, on_delete=models.PROTECT)
product = models.ForeignKey(Product, on_delete=models.PROTECT)
quantity = models.PositiveSmallIntegerField()
unit_price = models.DecimalField(max_digits=6, decimal_places=2)
class CartItem(models.Model):
cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveSmallIntegerField()