DRF Vote is a simple Django Rest Framework app to add ability to like/dislike a model.
You can read more about it on my blog
User must be logged-in to user user-specific apis.
Install votes:
pip install votes
Add
'votes'
to yourINSTALLED_APPS
setting like this:INSTALLED_APPS = ( ... 'votes', )
Run
python manage.py syncdb
to create the vote models.Declare vote field to the model you want to vote:
from votes.managers import VotableManager class ArticleReview(models.Model): ... votes = VotableManager()
Include votes url to your urls.py file:
from django.conf.urls import include from django.conf.urls import url from votes import urls urlpatterns += [ url(r'^', include(urls)), ]
This is extended version of repo django-vote
DRF Vote is a simple Django Rest Framework app to add ability to like/dislike a model.
You can read more about it on my blog post
- Modified to work with django rest framework.
- A new feature of disliking an object is added in this version.
Adds a new like or dislike vote to the object
param: model, id, vote i.e. model=movies&id=359&vote=true
vote=option[true for up-vote, false for down-vote, None for no-vote]
This api is used for both liking and disliking the object. Send vote=true for like vote=false for dislike
Removes vote to the object
- param: model, id i.e. model=movies&id=359
Check if the user already voted the object
- param: model, id i.e. model=movies&id=359
return all instances voted by user
- param: model, id i.e. model=movies&id=359
Returns the number of votes for the object
- param: model, id i.e. model=movies&id=359
Returns a list of users who voted and their voting date
- param: model, id i.e. model=movies&id=359
Returns the number of likes and dislikes for the object.
- param: model, id i.e. model=movies&id=359
Does the code actually work?
source <YOURVIRTUALENV>/bin/activate (myenv) $ pip install -r requirements-test.txt (myenv) $ python runtests.py
Tools used in rendering this package: