models.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from django.db import models
  2. class Product(models.Model):
  3. """
  4. Stores product details
  5. """
  6. item_id = models.CharField(max_length=100, unique=True)
  7. product_name = models.CharField(max_length=255)
  8. product_long_description = models.TextField(blank=True, null=True)
  9. product_short_description = models.TextField(blank=True, null=True)
  10. product_type = models.CharField(max_length=100, blank=True, null=True)
  11. image_path = models.CharField(max_length=500, blank=True, null=True)
  12. image = models.ImageField(upload_to='products/', blank=True, null=True)
  13. def __str__(self):
  14. return f"{self.product_name} ({self.item_id})"
  15. class ProductType(models.Model):
  16. name = models.CharField(max_length=100, unique=True)
  17. def __str__(self):
  18. return self.name
  19. class ProductAttribute(models.Model):
  20. product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE, related_name="attributes")
  21. name = models.CharField(max_length=100)
  22. is_mandatory = models.BooleanField(default=False)
  23. def __str__(self):
  24. return f"{self.product_type.name} - {self.name} ({'Mandatory' if self.is_mandatory else 'Additional'})"
  25. class AttributePossibleValue(models.Model):
  26. attribute = models.ForeignKey(ProductAttribute, on_delete=models.CASCADE, related_name="possible_values")
  27. value = models.CharField(max_length=255)
  28. def __str__(self):
  29. return f"{self.attribute.name}: {self.value}"