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.

enforcing_stock_rules.rst 520B

123456789101112
  1. Enforcing stock rules
  2. =====================
  3. You can enfore stock validation rules using signals. You just need to register a listener to
  4. the BasketLine pre_save signal that checks the line is valid. For example::
  5. @receiver(pre_save, sender=Line)
  6. def handle_line_save(sender, **kwargs):
  7. if 'instance' in kwargs:
  8. quantity = int(kwargs['instance'].quantity)
  9. if quantity > 4:
  10. raise InvalidBasketLineError("You are only allowed to purchase a maximum of 4 of these")