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

Helper to merge / append to history records #1296

Open
mjsir911 opened this issue Jan 23, 2024 · 0 comments
Open

Helper to merge / append to history records #1296

mjsir911 opened this issue Jan 23, 2024 · 0 comments

Comments

@mjsir911
Copy link
Contributor

mjsir911 commented Jan 23, 2024

Problem Statement

We've run in to the situation a few times where multiple .save()s need to be called in short succession / a single "change" and it would be convenient to be able to specify that these multiple saves should be recorded as a single history record.

We run into this same problem when tracking m2m changes too since those changes set off a signal that trigger creation of additional history records ( I think there's discussion about this in #399 )

Describe the solution you'd like

A few potential interfaces:

  • something like skip_history_when_saving but append_history_when_saving or similar
  • HistoryRecord.merge_with_previous() / HistoryRecord.merge_into_and_delete(record)
  • .history.merge_till(record)
  • some sort of context manager?

For all of these ways to go about this, what they would functionally do is just delete earlier records & potentially copy over date/user/change reason information.

One unanswered question is how multiple change reasons / change users on a record would work. Probably just have to arbitrarily choose to keep one (I would prefer to keep the change reason on the earliest history record)

Describe alternatives you've considered

Theoretically a workaround is temporarily not recording history then doing a final .save() with history recording enabled, or deleting each created record on a new .save(), or appending changes to an existing history record with .latest(). I'de just like to formalize a mechanism to do this & not have to reinvent ways to achieve this every time.

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