Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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")