Skip to content

Possible solution for admin inlines #1415

Open
@tomH01

Description

@tomH01

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions