Skip to content

Commit

Permalink
bump verion and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
shellfly committed Dec 17, 2022
1 parent b2e8eb4 commit 2b9aeaf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

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

#### Use vote API
### Use vote API

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

# Returns the number of down votes for the object
review.votes.count(action=DOWN)

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

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

```

#### Use `VoteMixin` for REST API
### Use tags template

There are two template tags you can use in template:
1. `vote_count` to get vote count for a model instance
2. `vote_exists` to check whether current user vote for the instance

``` html
{% load vote %}
<ol>
{% for comment in comments %}
<li>
{{comment.content}} - up:{% vote_count comment "up" %} - down: {% vote_count comment "down" %} - exists_up:
{% vote_exists comment user "up" %} - exists_down: {% vote_exists comment user "down"%}
</li>
{% endfor %}
</ol>
```

### Use `VoteMixin` for REST API

Install [django-rest-framework](https://github.com/encode/django-rest-framework/)

``` python
from rest_framework.viewsets import ModelViewSet
from vote.views import VoteMixin

class CommentViewSet(ModelViewSet, VoteMixin):
queryset = Comment.objects.all()
serializer_class = CommentSerializer
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

2.4.0 (2022.12.17)
------------------
* Add template tag to get vote count

2.3.0 (2022.02.06)
------------------
* Add support for Django 4.0
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10"
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11"
],
)
2 changes: 1 addition & 1 deletion test/templates/test/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% for comment in comments %}
<li>
{{comment.content}} - up:{% vote_count comment "up" %} - down: {% vote_count comment "down" %} - exists_up:
{%vote_exists comment user %} - exists_down: {% vote_exists comment user "down"%}
{%vote_exists comment user "up" %} - exists_down: {% vote_exists comment user "down"%}
</li>
{% endfor %}
</ol>
2 changes: 1 addition & 1 deletion vote/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (2, 3, 0)
VERSION = (2, 4, 0)

default_app_config = "vote.apps.VoteAppConfig"

0 comments on commit 2b9aeaf

Please sign in to comment.