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

INSTALLED_APPS = (
  ...
  'vote',
)

Add VoteModel to the model you want to vote

from vote.models import VoteModel

class ArticleReview(VoteModel, models.Model):
    ...

Run migrate

manage.py makemigrations
manage.py migrate

Use vote API

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

# Up vote to the object
review.votes.up(user_id)

# Down vote to the object
review.votes.down(user_id)

# Removes a vote from the object
review.votes.delete(user_id)

# Check if the user already voted (up) the object
review.votes.exists(user_id)

# 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
review.votes.count()

# Returns a list of users who voted and their voting date
review.votes.user_ids()


# Returns all instances voted by user
Review.votes.all(user_id)

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/

Project details


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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django-vote-2.3.0.tar.gz.

File metadata

  • Download URL: django-vote-2.3.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django-vote-2.3.0.tar.gz
Algorithm Hash digest
SHA256 1c8dfbea5d09ff4161a0500435ef010e2ce81638c21c5e9488d33db48dd16f6e
MD5 06afef608ef30946a1152f027b43d673
BLAKE2b-256 2cee36f8a53383e9cc26ec8c747550ad48f97ea1b0a9582e66102f076fa17735

See more details on using hashes here.

File details

Details for the file django_vote-2.3.0-py3-none-any.whl.

File metadata

  • Download URL: django_vote-2.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

File hashes

Hashes for django_vote-2.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0b0e830290f57928cb1340dbb51823a260b6a72317964b3282e0b84d81a945b
MD5 5b37043799f3844e08075b62ebd929d0
BLAKE2b-256 66b3c2f6d6b461ca2ba9dc6fe190b7e670cd202209ecef736aff0a7703c5b131

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page