Add support for logging reverse relations in Binder history #277
+306
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This PR adds the ability to include reverse relationships in the history log of a model. Previously, changes to a reverse ForeignKey (e.g., adding an Animal to a Zoo where the FK is on Animal would not appear in the Zoo's history.
Features
New Configuration Option: Added [include_reverse_relations] class options.
Reverse Relation Logging: When configured, the following actions on the child model now trigger a history entry on the parent model:
Implementation: Uses pre_save and pre-delete signals on the related (child) model to detect changes.
Utilizing DeferredM2M type to record these relation changes in the history changeset.
Documentation: Updated models.md with usage examples.
Testing: Added comprehensive tests test_reverse_relation_history.py and test_reverse_relation_no_child_history.py covering value changes, moves, and deletions. Validated that child models do not require history enabled for this feature to work on the parent.