-
Notifications
You must be signed in to change notification settings - Fork 490
Implement the ability to diff HistoricalRecords #416
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small changes/feedback. Looks great tho!
docs/advanced.rst
Outdated
History Diffing | ||
------------------- | ||
|
||
When you have two instances of the same HistoricalRecord (such as the HistoricalPoll example above), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format HistoricalRecord
and HistoricalPoll
docs/advanced.rst
Outdated
------------------- | ||
|
||
When you have two instances of the same HistoricalRecord (such as the HistoricalPoll example above), | ||
you can perform diffs to see what changed. This will result in a ModelDelta containing properties including |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format ModelDelta
docs/advanced.rst
Outdated
------------------- | ||
|
||
When you have two instances of the same HistoricalRecord (such as the HistoricalPoll example above), | ||
you can perform diffs to see what changed. This will result in a ModelDelta containing properties including |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will result in a ModelDelta
with the following properties:
- A of changes between each of the two historical records
- A list with the names of all fields that differed from one record to the other
- The old and new records
p.save() | ||
|
||
new_record, old_record = p.history.all() | ||
delta = new_record.diff_against(old_record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to add some more code examples that show what that delta
object contains – I wouldn't know what it has without looking through the code or inspecting the instance
simple_history/models.py
Outdated
class HistoricalChanges(object): | ||
def diff_against(self, old_history): | ||
if not isinstance(old_history, type(self)): | ||
raise TypeError(("unsupported operand type(s) for diffing: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove the operand
terminology here as we're no longer overriding -
simple_history/models.py
Outdated
type(self), | ||
type(old_history))) | ||
|
||
model_delta_class = getattr(self, 'model_delta_class', ModelDelta) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is here so that we can potentially override the default ModelDelta
with a different one? How would a user be able to set that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like setting it would be set as an attribute model_delta_class
on the class this is being mixed into. I don't see a compelling reason to support that so I'm happy to remove.
Can you also add this to the |
(Credit goes to leportella for the initial commit)
Codecov Report
@@ Coverage Diff @@
## master #416 +/- ##
=========================================
+ Coverage 97.21% 97.32% +0.1%
=========================================
Files 14 14
Lines 646 672 +26
Branches 89 93 +4
=========================================
+ Hits 628 654 +26
Misses 9 9
Partials 9 9
Continue to review full report at Codecov.
|
@rossmechanic can you folks release a new package version on PyPI containing this change? I would really like to use it without forking or copying pieces of the code. Thanks. |
@atodorov Just released version |
Description
This PR adds the ability to produce the difference between two HistoricalRecord instances.
Related Issue
#244
Motivation and Context
This change allows users to construct timelines of changes for a given record.
How Has This Been Tested?
Unit tests
Types of changes
Checklist:
(Credit goes to leportella for the initial commit)