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.

custom.py 688B

123456789101112131415161718192021222324252627
  1. from django.core import exceptions
  2. from oscar.apps.offer.models import Range, Condition
  3. def _class_path(klass):
  4. return '%s.%s' % (klass.__module__, klass.__name__)
  5. def create_range(range_class):
  6. """
  7. Create a custom range instance
  8. """
  9. if not hasattr(range_class, 'name'):
  10. raise exceptions.ValidationError(
  11. "A custom range must have a name attribute")
  12. return Range.objects.create(
  13. name=range_class.name,
  14. proxy_class=_class_path(range_class))
  15. def create_condition(condition_class):
  16. """
  17. Create a custom condition instance
  18. """
  19. return Condition.objects.create(
  20. proxy_class=_class_path(condition_class))