Track history of M2M fields [WIP] #370
Closed
+43
−2
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.
Yet another attempt of introducing many to many fields support for django-simple-history.
Today I rebased this with master. Before that I was using this for like two months, but it was rebased with
django-20
branch.Not sure when I will continue working on this, but for now I decided to share the code with you to collect some feedback and know if this is at least good direction.
Current solution is backward compatible, it means that m2m fields aren't tracked by default. Programmer needs to define which m2m fields should be tracked and pass them within
HistoricalRecords
field declaration (see api 1),Such field definition is detected by Django
makemigration
and it that will create new tableHistorical<M2mTroughModelName>
.Under the hood tracking version changes and creating historical entries is based on Django signals.
As this is WIP, the only working way of this feature is with the new decorator. This new decorator is a way to manipulate m2m relation and to track their history but without tracking history of original object (see api 2).
api 1. Defining which m2m fields should be tracked:
api 2. Saving with new decorator, that prevents from creating historical entry of base object:
Looking forward to see some comments. Thanks!