-
-
Notifications
You must be signed in to change notification settings - Fork 462
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
feat(HistoryRecords): prev and next attributes #365
feat(HistoryRecords): prev and next attributes #365
Conversation
Codecov Report
@@ Coverage Diff @@
## master #365 +/- ##
==========================================
+ Coverage 97.45% 97.47% +0.02%
==========================================
Files 15 15
Lines 590 595 +5
Branches 73 73
==========================================
+ Hits 575 580 +5
Misses 9 9
Partials 6 6
Continue to review full report at Codecov.
|
simple_history/models.py
Outdated
""" | ||
Get the previous history record for the instance. `None` if first. | ||
""" | ||
entry = self.instance |
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.
I don't love going from historical record to instance back to historical record. Ideally we'd avoid this. Maybe look to see what they do in cleanerversion
? https://github.com/rossmechanic/cleanerversion/blob/master/versions/models.py#L83
I think something similar to that on our historical tables would be a much cleaner solution
351352c
to
a2096b5
Compare
""" | ||
Get the next history record for the instance. `None` if last. | ||
""" | ||
return self.instance.history.filter( |
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.
Good feedback. This forced me to implement these in a much more efficient and clean way. Thanks!
@rossmechanic should be good for another review. If reasonable, I will add relevant docs. Thanks! |
@SpainTrain need to pass the |
a2096b5
to
2c254ea
Compare
derp ✅ |
2c254ea
to
9bfb2ed
Compare
docs added |
@SpainTrain Thanks. This looks way better to me at first glance. Going to spend some time playing around with it and get you comments by end of week. |
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.
lgtm! Thanks!
Mind adding your name to |
simple_history/models.py
Outdated
""" | ||
return self.instance.history.filter( | ||
Q(history_date__lt=self.history_date) | ||
).order_by('history_date').first() |
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 should reverse order by history date or take .last()
with the existing order. We should also use say 3 records in test_get_prev_record
/ test_get_next_record
and get the previous and next records of the last / first records, respectively, to ensure we catch this type of bug in the unit tests.
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.
Good catch @ncvc
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.
very good catch, thanks!
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.
Fix @ncvc 's bug. And edit AUTHORS.rst
and CHANGES.rst
- New attributes on history model retrieve previous and next records Closes jazzband#230
9bfb2ed
to
1597816
Compare
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.
Fix ncvc 's bug. And edit AUTHORS.rst and CHANGES.rst
✔️
simple_history/models.py
Outdated
""" | ||
return self.instance.history.filter( | ||
Q(history_date__lt=self.history_date) | ||
).order_by('history_date').first() |
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.
very good catch, thanks!
TODO
Changes
Closes #230
This change is