Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible solution for admin inlines #1415

Open
tomH01 opened this issue Oct 21, 2024 · 0 comments
Open

Possible solution for admin inlines #1415

tomH01 opened this issue Oct 21, 2024 · 0 comments

Comments

@tomH01
Copy link

tomH01 commented Oct 21, 2024

My company uses simple history as well. I found a solution to display the correct inlines in the admin (sketched below).
If you are interested in the solution, I would obtain approval from my company to contribute the solution.
However, the solutions has some workarounds that would be nice to be replaced firstly:

  • Always Save Inlines: All inlines have to be saved whenever the parent model is saved (solved by AlwaysSaveForm in the inline class). It would be better to handle this directly within django-simple-history.
  • Save Order: The standard Django save order has to be used (Parent first, Children afterward)

Solution Overview

Prerequisites:

  • Inlines are always within a ForeignKey relationship (Child points to Parent)
  • HistoricalModels deliver a version field history_id
  • When a Parent is changed a new historical parent record with a history_id is created
  • When modifying the inlines of a Parent, only the affected Children will have a new historical record

Implementation:

  1. Always Save Inlines: Use an AlwaysSaveForm to ensure all Children are saved whenever the Parent is saved.
  2. Mapping: For each foreign key of a Child add a new field in the historical child model to create a mapping to the Parent history_id:
  • Distiguish by history_type of Child: "No change", "Created (+)", "Deleted (-)", "Modified (~)"
  • If "No change" or "Created (+)" or "Modified (~)" then add latest Parent history_id
  • Else change nothing
  • Display the Inlines: Display the inlines with parts of Add support for admin inlines #315 while filtering them by their mapping field.
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

No branches or pull requests

1 participant