Skip to content

Latest commit

 

History

History
13 lines (11 loc) · 566 Bytes

enforcing_stock_rules.rst

File metadata and controls

13 lines (11 loc) · 566 Bytes

How to enforce stock rules

You can enforce stock validation rules using signals. You just need to register a listener to the BasketLine pre_save signal that checks the line is valid. For example:

@receiver(pre_save, sender=Line)
def handle_line_save(sender, **kwargs):
    if 'instance' in kwargs:
        quantity = int(kwargs['instance'].quantity)
        if quantity > 4:
            raise InvalidBasketLineError("You are only allowed to purchase a maximum of 4 of these")