Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

models.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. from django.utils import six
  2. from django.db import models
  3. from oscar.models.fields import AutoSlugField
  4. from oscar.apps.offer.models import Benefit, Condition
  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',
  13. separator=six.u("_"),
  14. uppercase=True)
  15. class BasketOwnerCalledBarry(Condition):
  16. class Meta:
  17. proxy = True
  18. app_label = 'tests'
  19. def is_satisfied(self, offer, basket):
  20. if not basket.owner:
  21. return False
  22. return basket.owner.first_name.lower() == 'barry'
  23. def can_apply_condition(self, product):
  24. return False
  25. class BaseOfferModel(models.Model):
  26. class Meta:
  27. abstract = True
  28. app_label = 'tests'
  29. class CustomBenefitModel(BaseOfferModel, Benefit):
  30. name = 'Test benefit'
  31. class Meta:
  32. proxy = True
  33. app_label = 'tests'
  34. def __str__(self):
  35. return self.name
  36. @property
  37. def description(self):
  38. return self.name
  39. class CustomConditionModel(Condition):
  40. name = 'Test condition'
  41. class Meta:
  42. proxy = True
  43. app_label = 'tests'
  44. def is_satisfied(self, offer, basket):
  45. return True
  46. def can_apply_condition(self, product):
  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'