from django.db import models
from django.utils import timezone
from django.contrib.auth.models import User

class Product(models.Model): 
    #primary key called as id will automatically be generated by django
    product_id = models.AutoField
    product_name = models.CharField(max_length=50)
    category = models.CharField(max_length=50 , default = '')
    subcategory = models.CharField(max_length=50 , default='')
    price = models.IntegerField(default=0)
    desc = models.CharField(max_length=150)
    pub_date = models.DateField() 
    image1 = models.ImageField(upload_to='Ecommerce/images' , default='')
    image2 = models.ImageField(upload_to='Ecommerce/images' , default='')
    image3 = models.ImageField(upload_to='Ecommerce/images' , default='')


    def __str__(self): 
        return self.product_name 

class Review(models.Model): 
    for_product = models.ForeignKey(Product , related_name= 'for_product', on_delete = models.CASCADE)
    Name = models.CharField(max_length=50 , default='')
    Review = models.TextField()
    Date = models.DateTimeField(default = timezone.now())

    def __str__(self): 
        return self.Name

class Cart(models.Model):
    Item = models.ForeignKey(Product , on_delete = models.CASCADE)
    foruser = models.CharField(max_length = 50 ,default = '')
    quantity = models.IntegerField(default=1)
    price = models.IntegerField(default=0)
    
    def __str__(self): 
        return self.Item.product_name  #Refering to the Product class with name product_name  