Skip to content

Simple youtube like up and down rating app for Django.

License

Notifications You must be signed in to change notification settings

agusmakmun/django-updown-ratings

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

82 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-updown-ratings

Simple Django application for adding Youtube like up and down voting.
This django-updown-ratings is forked from django-updown to support the newest django version.

build status django version python version

Install

pip install django-updown-ratings

Usage

Add "updown" to your INSTALLED_APPS. Then just add a RatingField to your existing model:

from django.db import models
from updown.fields import RatingField

class Post(models.Model):
    # ...other fields...
    rating = RatingField()

You can also allow the user to change his vote:

class Post(models.Model):
    # ...other fields...
    rating = RatingField(can_change_vote=True)

Now you can write your own view to submit ratings or use the predefined:

from updown.views import AddRatingFromModel

urlpatterns = [
    ....

    path('<int:object_id>/rate/<str:score>', AddRatingFromModel(), {
        'app_label': 'blogapp',
        'model': 'Post',
        'field_name': 'rating'
    }, name='post_rating'),
]

To submit a vote just go to post/<id>/rate/(1|-1). If you allowed users to change they're vote, they can do it with the same url.

Template

You can directly use this properties in the template, e.g:

{{ post.rating.likes }}
{{ post.rating.dislikes }}
{{ post.rating.get_difference }}
{{ post.rating.get_quotient }}

Properties:

  • .likes show total likes
  • .dislikes show total dislikes
  • .get_difference get diff between likes and dislikes (likes - dislikes).
  • .get_quotient get quotient between likes and dislikes (likes / max(dislikes)).

About

Simple youtube like up and down rating app for Django.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%