Giter Site home page Giter Site logo

madscientist996 / django-vote Goto Github PK

View Code? Open in Web Editor NEW

This project forked from formator/django-vote

0.0 0.0 0.0 120 KB

Simple vote for django

Home Page: http://django-vote.readthedocs.io

License: BSD 3-Clause "New" or "Revised" License

Python 99.67% HTML 0.33%

django-vote's Introduction

Django Vote

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

This project is inspired by django-taggit

Build Status 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 the object
review.votes.exists(user_id)

# 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/

django-vote's People

Contributors

shellfly avatar tooooolong avatar ialex avatar philippeluickx avatar johnnyzhao avatar doctorjohn avatar willskywalker avatar jpic avatar formator avatar pushplataranjan avatar mozillazg avatar pivolan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.