@@ -24,16 +24,27 @@ class UserAccount(LifecycleModel):
2424
2525 @hook (AFTER_UPDATE )
2626 def on_name_change_heck_on_marital_status (self ):
27- if self .has_changed(' last_name' ) and not self .has_changed(' marital_status' ):
28- send_mail(to = self .email, " Has your marital status changed recently?" )
27+ if (
28+ self .has_changed(' last_name' )
29+ and not self .has_changed(' marital_status' )
30+ ):
31+ send_mail(
32+ to = self .email,
33+ " Has your marital status changed recently?"
34+ )
2935
3036```
3137
3238## Custom conditions <a id =" custom-conditions " ></a >
3339Custom conditions can be created as long as they respect condition signature
3440``` python
35- def changes_to_ned_flanders (instance , update_fields = None ):
36- ...
41+ def changes_to_ned_flanders (instance , update_fields = None ) -> bool :
42+ return (
43+ instance.has_changed(" first_name" )
44+ and instance.has_changed(" last_name" )
45+ and instance.first_name == " Ned"
46+ and instance.last_name == " Flanders"
47+ )
3748```
3849
3950To allow your custom conditions to be chainable, create a class based condition inheriting ` ChainableCondition ` .
@@ -45,12 +56,19 @@ from django_lifecycle.conditions.base import ChainableCondition
4556
4657class IsNedFlanders (ChainableCondition ):
4758 def __call__ (self , instance , update_fields = None ):
48- return instance.first_name == " Ned" and instance.last_name == " Flanders"
59+ return (
60+ instance.first_name == " Ned"
61+ and instance.last_name == " Flanders"
62+ )
4963
5064
5165@hook (
5266 BEFORE_SAVE ,
53- condition = WhenFieldHasChanged(" first_name" ) & WhenFieldHasChanged(" last_name" ) & IsNedFlanders()
67+ condition = (
68+ WhenFieldHasChanged(" first_name" )
69+ & WhenFieldHasChanged(" last_name" )
70+ & IsNedFlanders()
71+ )
5472)
5573def foo ():
5674 ...
0 commit comments