Django_Model

# null=False---> Null rakta par bo na
  # null=True---> Null rakta par bo
  # default=0---> default value "0" set kora66i
# blank=True--------->Jadi ki66u value na day tahola o save hoya jaba

  from django.db import models


CATEGORY_CHOICES = (

 ('M', 'Mobile'),

 ('L', 'Laptop'),

 ('TW', 'Top Wear'),

 ('BW', 'Bottom Wear'),

)


Product Model

class Product(models.Model):

 title = models.CharField(max_length=100)

 selling_price = models.FloatField()

 discounted_price = models.FloatField()

 description = models.TextField()

 brand = models.CharField(max_length=100)

 category = models.CharField(choices=CATEGORY_CHOICES, max_length=2)

 product_image = models.ImageField(upload_to='productimg')


 def __str__(self):

  return str(self.id)


  class Meta:
    ordering=['-pk']

  

 Cart Model

class Cart(models.Model):

 user = models.ForeignKey(User, on_delete=models.CASCADE)

 product = models.ForeignKey(Product, on_delete=models.CASCADE)

 quantity = models.PositiveIntegerField(default=1)


 def __str__(self):

  return str(self.id)


Or

Models/

__init__.py

product.py

cart.py


__init__.py

from .products import Product

from .catagory import Category

from .orders import Order

from .customer import Customer

Comments