Skip to content

Commit 2b9aeaf

Browse files
committed
bump verion and update README
1 parent b2e8eb4 commit 2b9aeaf

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
This project is inspired by [django-taggit](https://github.com/alex/django-taggit)
5+
This project was inspired by [django-taggit](https://github.com/alex/django-taggit)
66

77
![Ci](https://github.com/shellfly/django-vote/actions/workflows/ci.yml/badge.svg)
88
[![codecov](https://codecov.io/gh/shellfly/django-vote/branch/master/graph/badge.svg)](https://codecov.io/gh/shellfly/django-vote)
@@ -41,7 +41,7 @@ manage.py makemigrations
4141
manage.py migrate
4242
```
4343

44-
#### Use vote API
44+
### Use vote API
4545

4646
```python
4747
review = ArticleReview.objects.get(pk=1)
@@ -65,6 +65,9 @@ review.votes.exists(user_id, action=DOWN)
6565
# Returns the number of votes for the object
6666
review.votes.count()
6767

68+
# Returns the number of down votes for the object
69+
review.votes.count(action=DOWN)
70+
6871
# Returns a list of users who voted and their voting date
6972
review.votes.user_ids()
7073

@@ -74,9 +77,32 @@ Review.votes.all(user_id)
7477

7578
```
7679

77-
#### Use `VoteMixin` for REST API
80+
### Use tags template
81+
82+
There are two template tags you can use in template:
83+
1. `vote_count` to get vote count for a model instance
84+
2. `vote_exists` to check whether current user vote for the instance
85+
86+
``` html
87+
{% load vote %}
88+
<ol>
89+
{% for comment in comments %}
90+
<li>
91+
{{comment.content}} - up:{% vote_count comment "up" %} - down: {% vote_count comment "down" %} - exists_up:
92+
{% vote_exists comment user "up" %} - exists_down: {% vote_exists comment user "down"%}
93+
</li>
94+
{% endfor %}
95+
</ol>
96+
```
97+
98+
### Use `VoteMixin` for REST API
99+
100+
Install [django-rest-framework](https://github.com/encode/django-rest-framework/)
78101

79102
``` python
103+
from rest_framework.viewsets import ModelViewSet
104+
from vote.views import VoteMixin
105+
80106
class CommentViewSet(ModelViewSet, VoteMixin):
81107
queryset = Comment.objects.all()
82108
serializer_class = CommentSerializer

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
=========
33

4+
2.4.0 (2022.12.17)
5+
------------------
6+
* Add template tag to get vote count
7+
48
2.3.0 (2022.02.06)
59
------------------
610
* Add support for Django 4.0

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"Programming Language :: Python :: 3.7",
3939
"Programming Language :: Python :: 3.8",
4040
"Programming Language :: Python :: 3.9",
41-
"Programming Language :: Python :: 3.10"
41+
"Programming Language :: Python :: 3.10",
4242
"Programming Language :: Python :: 3.11"
4343
],
4444
)

test/templates/test/comments.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% for comment in comments %}
44
<li>
55
{{comment.content}} - up:{% vote_count comment "up" %} - down: {% vote_count comment "down" %} - exists_up:
6-
{%vote_exists comment user %} - exists_down: {% vote_exists comment user "down"%}
6+
{%vote_exists comment user "up" %} - exists_down: {% vote_exists comment user "down"%}
77
</li>
88
{% endfor %}
99
</ol>

vote/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (2, 3, 0)
1+
VERSION = (2, 4, 0)
22

33
default_app_config = "vote.apps.VoteAppConfig"

0 commit comments

Comments
 (0)