Skip to content

Commit b00d7de

Browse files
committed
previous_values_are_unequal
1 parent 1e961b2 commit b00d7de

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

codeforlife/models/signals/post_save.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def check_previous_values(
2020
):
2121
# pylint: disable=line-too-long
2222
"""Check if the previous values are as expected. If the previous value's key
23-
is not on the model, this check returns false.
23+
is not on the model, this check returns False.
2424
2525
Args:
2626
instance: The current instance.
@@ -42,6 +42,31 @@ def check_previous_values(
4242
return True
4343

4444

45+
def previous_values_are_unequal(instance: _.AnyModel, fields: t.Set[str]):
46+
# pylint: disable=line-too-long
47+
"""Check if all the previous values are not equal to the current values. If
48+
the previous value's key is not on the model, this check returns False.
49+
50+
Args:
51+
instance: The current instance.
52+
fields: The fields that should not be equal.
53+
54+
Returns:
55+
If all the previous values are not equal to the current values.
56+
"""
57+
# pylint: enable=line-too-long
58+
59+
for field in fields:
60+
previous_value_key = PREVIOUS_VALUE_KEY.format(field=field)
61+
62+
if not hasattr(instance, previous_value_key) or (
63+
getattr(instance, field) == getattr(instance, previous_value_key)
64+
):
65+
return False
66+
67+
return True
68+
69+
4570
def get_previous_value(
4671
instance: _.AnyModel, field: str, cls: t.Type[FieldValue]
4772
):

0 commit comments

Comments
 (0)