{"id":19979190,"url":"https://github.com/shellfly/django-vote","last_synced_at":"2025-04-05T05:09:58.508Z","repository":{"id":18382872,"uuid":"21563725","full_name":"shellfly/django-vote","owner":"shellfly","description":"Simple vote for django","archived":false,"fork":false,"pushed_at":"2024-06-20T16:03:03.000Z","size":109,"stargazers_count":159,"open_issues_count":11,"forks_count":49,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-03-29T04:12:02.256Z","etag":null,"topics":["django","django-vote","python","vote"],"latest_commit_sha":null,"homepage":"http://django-vote.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shellfly.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-07T08:51:42.000Z","updated_at":"2025-01-07T04:22:58.000Z","dependencies_parsed_at":"2025-01-11T22:11:13.121Z","dependency_job_id":null,"html_url":"https://github.com/shellfly/django-vote","commit_stats":{"total_commits":126,"total_committers":17,"mean_commits":7.411764705882353,"dds":"0.46031746031746035","last_synced_commit":"e8449bee22a205d2673b2b5ee174d4bf5e5368ff"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellfly%2Fdjango-vote","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellfly%2Fdjango-vote/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellfly%2Fdjango-vote/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shellfly%2Fdjango-vote/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shellfly","download_url":"https://codeload.github.com/shellfly/django-vote/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289429,"owners_count":20914464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-vote","python","vote"],"created_at":"2024-11-13T03:37:08.255Z","updated_at":"2025-04-05T05:09:58.489Z","avatar_url":"https://github.com/shellfly.png","language":"Python","readme":"## Django Vote\n\n``django-vote`` is a simple Django app to conduct vote for django model.\n\nThis project was inspired by [django-taggit](https://github.com/alex/django-taggit)\n\n![Ci](https://github.com/shellfly/django-vote/actions/workflows/ci.yml/badge.svg)\n[![codecov](https://codecov.io/gh/shellfly/django-vote/branch/master/graph/badge.svg)](https://codecov.io/gh/shellfly/django-vote)\n[![PyPI version](https://badge.fury.io/py/django-vote.svg)](https://badge.fury.io/py/django-vote)\n\n### Quick start\n\n#### Install `django-vote` by pip\n\n```shell\npip install django-vote\n```\n\n#### Add `'vote'` to your `INSTALLED_APPS` setting like this\n\n```python\nINSTALLED_APPS = (\n  ...\n  'vote',\n)\n```\n\n#### Add `VoteModel` to the model you want to vote\n\n```python\nfrom vote.models import VoteModel\n\nclass ArticleReview(VoteModel, models.Model):\n    ...\n```\n\n#### Run migrate\n\n```shell\nmanage.py makemigrations\nmanage.py migrate\n```\n\n### Use vote API\n\n```python\nreview = ArticleReview.objects.get(pk=1)\n\n# Up vote to the object\nreview.votes.up(user_id)\n\n# Down vote to the object\nreview.votes.down(user_id)\n\n# Removes a vote from the object\nreview.votes.delete(user_id)\n\n# Check if the user already voted (up) the object\nreview.votes.exists(user_id)\n\n# Check if the user already voted (down) the object\n# import UP, DOWN from vote.models\nreview.votes.exists(user_id, action=DOWN)\n\n# Returns the number of votes for the object\nreview.votes.count()\n\n# Returns the number of down votes for the object\nreview.votes.count(action=DOWN)\n\n# Returns a list of users who voted and their voting date\nreview.votes.user_ids()\n\n\n# Returns all instances voted by user\nReview.votes.all(user_id)\n\n```\n\n### Use template tags\n\nThere are two template tags you can use in template: \n1. `vote_count` to get vote count for a model instance\n2. `vote_exists` to check whether current user vote for the instance\n\n``` html\n{% load vote %}\n\u003col\u003e\n    {% for comment in comments %}\n    \u003cli\u003e\n        {{comment.content}} - up:{% vote_count comment \"up\" %} - down: {% vote_count comment \"down\" %} - exists_up:\n        {% vote_exists comment user \"up\" %} - exists_down: {% vote_exists comment user \"down\"%}\n    \u003c/li\u003e\n    {% endfor %}\n\u003c/ol\u003e\n```\n\n### Use `VoteMixin` for REST API\n\nInstall [django-rest-framework](https://github.com/encode/django-rest-framework/)\n\n``` python\nfrom rest_framework.viewsets import ModelViewSet\nfrom vote.views import VoteMixin\n\nclass CommentViewSet(ModelViewSet, VoteMixin):\n    queryset = Comment.objects.all()\n    serializer_class = CommentSerializer\n```\n\n```sh\nPOST /api/comments/{id}/vote/\nPOST /api/comments/{id}/vote/ {\"action\":\"down\"}\nDELETE /api/comments/{id}/vote/\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellfly%2Fdjango-vote","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshellfly%2Fdjango-vote","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshellfly%2Fdjango-vote/lists"}