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.

models.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from django.contrib.auth.models import User
  2. from django.db import models
  3. from django.utils.translation import ugettext as _
  4. class ConditionalOffer(models.Model):
  5. name = models.CharField(max_length=128)
  6. description = models.TextField(blank=True)
  7. condition = models.ForeignKey('offer.Condition')
  8. benefit = models.ForeignKey('offer.Benefit')
  9. start_date = models.DateField()
  10. # Offers can be open-ended
  11. end_date = models.DateField(blank=True)
  12. priority = models.IntegerField()
  13. created_date = models.DateTimeField(auto_now_add=True)
  14. class Condition(models.Model):
  15. COUNT, VALUE = ("Count", "Value")
  16. TYPE_CHOICES = (
  17. (COUNT, _("Depends on number of items in basket that are in condition range")),
  18. (VALUE, _("Depends on value of items in basket that are in condition range")),
  19. )
  20. range = models.ForeignKey('offer.Range')
  21. type = models.CharField(max_length=128, choices=TYPE_CHOICES)
  22. value = models.FloatField()
  23. class Benefit(models.Model):
  24. PERCENTAGE, FIXED = ("Percentage", "Absolute")
  25. TYPE_CHOICES = (
  26. (PERCENTAGE, _("Discount is a % of the product's value")),
  27. (FIXED, _("Discount is a fixed amount off the product's value")),
  28. )
  29. range = models.ForeignKey('offer.Range')
  30. type = models.CharField(max_length=128, choices=TYPE_CHOICES)
  31. value = models.FloatField()
  32. class Range(models.Model):
  33. name = models.CharField(max_length=128)
  34. includes_all_products = models.BooleanField(default=False)
  35. included_products = models.ManyToManyField('product.Item', related_name='includes')
  36. excluded_products = models.ManyToManyField('product.Item', related_name='excludes')
  37. class Voucher(models.Model):
  38. """
  39. A voucher
  40. """
  41. code = models.CharField(max_length=128)
  42. start_date = models.DateField()
  43. end_date = models.DateField()
  44. offers = models.ManyToManyField('offer.ConditionalOffer')
  45. created_date = models.DateTimeField(auto_now_add=True)