Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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