Reputation: 2417
I am exploring models in django where I am trying to create a model for e-commerce product. The schema that I have designed is follow for now
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=80)
def __str__(self):
return self.name
class Product(models.Model):
name = models.CharField(max_length=100)
category = models.ForeignKey(Category, on_delete=models.CASCADE)
total_stock = models.PositiveIntegerField(default=0)
def __str__(self):
return self.name
class Attribute(models.Model):
'''
attribute can be like color, material, size and many more
'''
name = models.CharField(max_length=80)
def __str__(self):
return self.name
class AttributeValue(models.Model):
'''
Values for the selected attribute like for size attr
the values can be Large, Medium, Small and etc
'''
name = models.CharField(max_length=100)
attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
price = models.DecimalField(decimal_places=2, max_digits=10)
discount = models.DecimalField(decimal_places=2, max_digits=10)
stock = models.PositiveIntegerField(default=0)
def __str__(self):
return self.name
class ProductAttribute(models.Model):
'''
Associate Particular attribute to Particular product
'''
product = models.ForeignKey(Product, on_delete=models.CASCADE)
attribute = models.ForeignKey(Attribute, on_delete=models.CASCADE)
def __str__(self):
return self.product.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
image = models.ImageField(upload_to = 'pic_folder/')
def __str__(self):
return self.product.name
My question is when I researched for scalable e-commerce product design (scalable in terms of better table relation and covering most of the factors in e-commerce), I saw various tables like
ProductVariant
, ProductVariantImage
, ProductOptions
and etc. So I got confused on those terminology. Can anyone help me to make me understand that with example and how can i adjust those table in my models.py
?
Here is the link
https://i.sstatic.net/5HCqo.png
Upvotes: 2
Views: 1136
Reputation: 1653
I think you just want to understand the terms and how they relate to each other, correct? And once you understand, you can decide how to adjust the schema & models.
ProductVariant: A "version" of the Product. From an e-commerce point of view, this can mean something that doesn't neatly fit into the Attribute or AttributeValue models. For example, a product can have a variant:
I think you can do without a ProductVariant model, and just get things to work using attributes. It may be meaningful to use ProductVariant as a reference to a pre-existing Product (foreign key constraint on Product.id). See here and here.
ProductVariantImage: A version of the ProductImage.
ProductOptions: The options for the Product. You can just use Attributes instead. This table/model doesn't seem to be any different than what Attributes & AttributeValues already have.
Upvotes: 1