Skip to main content

A simple Django app to conduct vote.

Project description

Django Vote

django-vote is a simple Django app to conduct vote for django model.

This project is inspired by django-taggit

Ci codecov PyPI version

Quick start

Install django-vote by pip

pip install django-vote

Add 'vote' to your INSTALLED_APPS setting like this


Add VoteModel to the model you want to vote

from vote.models import VoteModel

class ArticleReview(VoteModel, models.Model):

Run migrate makemigrations migrate

Use vote API

review = ArticleReview.objects.get(pk=1)

# Up vote to the object

# Down vote to the object

# Removes a vote from the object

# Check if the user already voted (up) the object

# Check if the user already voted (down) the object
# import UP, DOWN from vote.models
review.votes.exists(user_id, action=DOWN)

# Returns the number of votes for the object

# Returns a list of users who voted and their voting date

# Returns all instances voted by user

Use VoteMixin for REST API

class CommentViewSet(ModelViewSet, VoteMixin):
    queryset = Comment.objects.all()
    serializer_class = CommentSerializer
POST /api/comments/{id}/vote/
POST /api/comments/{id}/vote/ {"action":"down"}
DELETE /api/comments/{id}/vote/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-vote-2.3.0.tar.gz (19.1 kB view hashes)

Uploaded source

Built Distribution

django_vote-2.3.0-py3-none-any.whl (14.1 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page