Skip to content

Comments

Add support for logging reverse relations in Binder history#277

Merged
knokko merged 2 commits intoCodeYellowBV:masterfrom
Jvdputten:history-reverse-relation-support
Feb 12, 2026
Merged

Add support for logging reverse relations in Binder history#277
knokko merged 2 commits intoCodeYellowBV:masterfrom
Jvdputten:history-reverse-relation-support

Conversation

@Jvdputten
Copy link

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:

    • Creation: Creating a new child object linked to the parent.
    • Deletion: Deleting a child object linked to the parent.
    • Reassignment: Moving a child object from one parent to another (logs removal on old parent, addition on new parent).
  • 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.

@Jvdputten Jvdputten force-pushed the history-reverse-relation-support branch from 9418395 to 2bd0875 Compare February 2, 2026 07:24
@Jvdputten Jvdputten force-pushed the history-reverse-relation-support branch from 2bd0875 to 41e6b89 Compare February 2, 2026 07:40
@knokko knokko merged commit 64eeff5 into CodeYellowBV:master Feb 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants