Add support for logging reverse relations in Binder history#277
Open
Jvdputten wants to merge 2 commits intoCodeYellowBV:masterfrom
Open
Add support for logging reverse relations in Binder history#277Jvdputten wants to merge 2 commits intoCodeYellowBV:masterfrom
Jvdputten wants to merge 2 commits intoCodeYellowBV:masterfrom
Conversation
9418395 to
2bd0875
Compare
2bd0875 to
41e6b89
Compare
| ) | ||
|
|
||
| # This is Postgres-specific | ||
| if os.environ.get('BINDER_TEST_MYSQL', '0') != '1': |
Author
There was a problem hiding this comment.
Sorry that was automatic formatting due to Ruff. Will revert (Highly recommend it though).
| return | ||
|
|
||
| try: | ||
| parent = getattr(instance, fk_name) |
There was a problem hiding this comment.
I feel like it makes sense to make sure that, if the dev fills in a non-existant relation, that the system will raise an error to warn the dev
…formatting in tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.