-
Notifications
You must be signed in to change notification settings - Fork 49
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
Swappable Vote model #85
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #85 +/- ##
==========================================
- Coverage 92.82% 90.80% -2.03%
==========================================
Files 8 9 +1
Lines 223 250 +27
Branches 23 27 +4
==========================================
+ Hits 207 227 +20
- Misses 13 19 +6
- Partials 3 4 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@harikvpy Hi, thanks for considering making contribution back to this repo, and I can see the swappable feature could be useful in some cases. However this change introduces a third library I can accept this change if you could make it an optional feature like the |
Thanks for the quick feedback. What you raise is indeed a valid concern. It should be fairly simple to make the swappable model mechanism an optional feature. I'll have a look and revert this week. |
Swapper package is optional now. The test env have been updated to cover both environments -- with An unintended consequence of this is that code coverage comes down a little as the conditional import code cannot be tested in the without |
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.
thanks for the updating, I have a few comments, PTAL
@@ -53,7 +53,9 @@ def __init__(self, through, model, instance, field_name='votes'): | |||
self.field_name = field_name | |||
|
|||
def vote(self, user_id, action): | |||
'''Returns the Vote object on success. None on failure.''' |
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 a breaking change for users who are using this API, why do you change this?
|
||
UP = 0 | ||
DOWN = 1 |
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 also a breaking change that users' code could be broken after upgrading if they use this variable.
django40: Django==4.0 | ||
djangorestframework | ||
swapper: swapper==1.3.0 | ||
commands = ./runtests_swapped.py |
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.
It seems there are many duplications with the current Github CI setup, could we use GitHub action to do this?
I had a requirement to add a field to Vote model and I first forked the code as a private app into my project. Then decided to try implementing the same using Django's swappable model infrastructure. This PR incorporates all the changes related to this.
The files affected might seem quite long, but they are mostly because of code re-org.
models.py
had to be split intobase_models.py
andmodels.py
and this required touching all the files that importedmodels.py
.I have updated the README and the tests. The tests now cover swapped model use-case. Essentially the same tests are repeated using a swapped
Vote
model.Pls review the code and if you think it's worth it, you may merge it.