You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from django.db import models
  2. class AttributeType(models.Model):
  3. """Defines a product atrribute type"""
  4. name = models.CharField(max_length = 128)
  5. def __unicode__(self):
  6. return self.name
  7. class Type(models.Model):
  8. """Defines a product type"""
  9. name = models.CharField(max_length = 128)
  10. attribute_types = models.ManyToManyField('product.AttributeType')
  11. def __unicode__(self):
  12. return self.name
  13. class Item(models.Model):
  14. """The base product object"""
  15. name = models.CharField(max_length = 128)
  16. partner_id = models.CharField(max_length = 32)
  17. type = models.ForeignKey('product.Type')
  18. date_available = models.DateField()
  19. date_created = models.DateTimeField()
  20. def __unicode__(self):
  21. return self.name
  22. def is_valid(self):
  23. """
  24. Returns true if the product is valid.
  25. Validity is based on whether the product has all required attribute types
  26. configured for the product_class it is in.
  27. Returns:
  28. A boolean if the product is valid
  29. """
  30. required_attribute_names = []
  31. for attribute_type in self.type.attribute_types.all():
  32. required_attribute_names.append(attribute_type.name)
  33. for attribute in self.attribute_set.all():
  34. required_attribute_names.remove(attribute.attribute_type.name)
  35. return 0 == len(required_attribute_names)
  36. class Attribute(models.Model):
  37. """An individual product attribute"""
  38. attribute_type = models.ForeignKey('product.AttributeType')
  39. product = models.ForeignKey('product.Item')
  40. value = models.CharField(max_length = 256)
  41. class StockRecord(models.Model):
  42. """A stock keeping record"""
  43. product = models.ForeignKey('product.Item')
  44. price_excl_tax = models.FloatField()
  45. tax = models.FloatField()