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

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