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 566B

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