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 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. from django.db import models
  2. from oscar.apps.address.models import UserAddress
  3. from oscar.apps.offer.models import Benefit, Condition
  4. from oscar.models.fields import AutoSlugField
  5. class SluggedTestModel(models.Model):
  6. title = models.CharField(max_length=42)
  7. slug = AutoSlugField(populate_from="title")
  8. class ChildSluggedTestModel(SluggedTestModel):
  9. pass
  10. class CustomSluggedTestModel(models.Model):
  11. title = models.CharField(max_length=42)
  12. slug = AutoSlugField(populate_from="title", separator="_", uppercase=True)
  13. class BasketOwnerCalledBarry(Condition):
  14. class Meta:
  15. proxy = True
  16. app_label = "tests"
  17. def is_satisfied(self, offer, basket):
  18. if not basket.owner:
  19. return False
  20. return basket.owner.first_name.lower() == "barry"
  21. # pylint: disable=unused-argument
  22. def can_apply_condition(self, line):
  23. return False
  24. class BaseOfferModel(models.Model):
  25. class Meta:
  26. abstract = True
  27. app_label = "tests"
  28. class CustomBenefitModel(BaseOfferModel, Benefit):
  29. name = "Test benefit"
  30. class Meta:
  31. proxy = True
  32. app_label = "tests"
  33. def __str__(self):
  34. return self.name
  35. @property
  36. def description(self):
  37. return self.name
  38. class CustomConditionModel(Condition):
  39. name = "Test condition"
  40. class Meta:
  41. proxy = True
  42. app_label = "tests"
  43. def is_satisfied(self, offer, basket):
  44. return True
  45. # pylint: disable=unused-argument
  46. def can_apply_condition(self, line):
  47. return True
  48. class CustomBenefitWithoutName(Benefit):
  49. class Meta:
  50. proxy = True
  51. app_label = "tests"
  52. description = "test"
  53. class CustomConditionWithoutName(Condition):
  54. class Meta:
  55. proxy = True
  56. app_label = "tests"
  57. class UserAddressModelWithCustomBaseFields(UserAddress):
  58. class Meta:
  59. proxy = True
  60. app_label = "tests"
  61. base_fields = ["line1", "line4"]
  62. class UserAddressModelWithCustomHashFields(UserAddress):
  63. class Meta:
  64. proxy = True
  65. app_label = "tests"
  66. hash_fields = ["line1", "line4"]