from django.db import models class Product(models.Model): """ Stores product details """ item_id = models.CharField(max_length=100, unique=True) product_name = models.CharField(max_length=255) product_long_description = models.TextField(blank=True, null=True) product_short_description = models.TextField(blank=True, null=True) product_type = models.CharField(max_length=100, blank=True, null=True) image_path = models.CharField(max_length=500, blank=True, null=True) image = models.ImageField(upload_to='products/', blank=True, null=True) def __str__(self): return f"{self.product_name} ({self.item_id})" # models.py class ProductAttributeValue(models.Model): """ Stores manually entered original attribute values for products """ product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name="attribute_values") attribute_name = models.CharField(max_length=100) original_value = models.TextField() created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) class Meta: unique_together = ['product', 'attribute_name'] def __str__(self): return f"{self.product.item_id} - {self.attribute_name}: {self.original_value}" class ProductType(models.Model): name = models.CharField(max_length=100, unique=True) def __str__(self): return self.name class ProductAttribute(models.Model): product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE, related_name="attributes") name = models.CharField(max_length=100) is_mandatory = models.BooleanField(default=False) def __str__(self): return f"{self.product_type.name} - {self.name} ({'Mandatory' if self.is_mandatory else 'Additional'})" class AttributePossibleValue(models.Model): attribute = models.ForeignKey(ProductAttribute, on_delete=models.CASCADE, related_name="possible_values") value = models.CharField(max_length=255) def __str__(self): return f"{self.attribute.name}: {self.value}"