diff --git a/README.md b/README.md index f2a0c1d..c64b0dd 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,10 @@ Using the `ChangeDetectionMixin` the pydantic models are extended, so: changed fields. **Note:** When using pydantic 1.x you need to use `obj.dict()` and `obj.json()`. Both also accept `exclude_unchanged`. +* `obj.model_mark_changed("marker_name")` and `obj.model_unmark_changed("marker_name")` + allow to add arbitrary change markers. An instance with a marker will be seen as changed + (`obj.model_has_changed == True`). Markers are stored in `obj.model_changed_markers` + as a set. ### Example @@ -63,6 +67,31 @@ value to `model_set_changed()` when you want to also keep track of the actual ch compared to the original value. Be advised to `.copy()` the original value as lists/dicts will always be changed in place. +### Changed markers + +You may also just mark the model as changed. This can be done using changed markers. +A change marker is just a string that is added as the marker, models with such an marker +will also be seen as changed. Changed markers also allow to mark models as changed when +related data was changed - for example to also update a parent object in the database +when some children were changed. + +```python +import pydantic +from pydantic_changedetect import ChangeDetectionMixin + +class Something(ChangeDetectionMixin, pydantic.BaseModel): + name: str + + +something = Something(name="something") +something.model_has_changed # = False +something.model_mark_changed("mood") +something.model_has_changed # = True +something.model_changed_markers # {"mood"} +something.model_unmark_changed("mood") # also will be reset on something.model_reset_changed() +something.model_has_changed # = False +``` + # Contributing If you want to contribute to this project, feel free to just fork the project,