I have a product model:
class Product(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
category = models.ForeignKey('Category', on_delete=models.CASCADE)
price = models.FloatField()
discount = models.IntegerField() # stands for percentage
count = models.IntegerField()
priority = models.IntegerField(default=0)
brand = models.ForeignKey('Brand', on_delete=models.SET_NULL, null=True, blank=True)
tags = models.ManyToManyField(Tag, blank=True)
def __str__(self):
return self.title
Now I want to implement entity attribute value pattern as different products can have different specifications. I understood the traditional way of EAV. But I read in wikipedia as postgresql has jsonb column type and this allows performance improvements by factors of a thousand or more over traditional EAV table designs. My database in postgresql. So what is the best practice to implement EAV (or dynamic set relationship with attributes)? Should I just add like:
class ProductVariant(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
specifications = models.JSONField()
And also I want to handle price and count (in stock) differently for each variant, let’s say there are 10 shoes with size 10 and color red which price is 100 dollars and 2 shoes with size 9 and color blue which price is 120 dollars.