I'm trying to include a youtube like up and down voting feature for my blog. I have used pip install django-updown
to install this to my project. I have followed all the instructions there.
I have included updown
to INSTALLED_APPS
, included rating = RatingField()
to my models.py
file and also included the url
as described. But, the problem is, I can't see the voting system in my blog? I'm guessing it is something to do with the template file since nothing has been mentioned about it.
I have the following commenting form in my template and would like the up-down vote to be shown before this. Can anyone help me out? Thanks :)
<div class="comment_form">
{% if user.is_authenticated %}
{% get_comment_form for object as form %}
.....
{% else %}
<p>Please log in to leave a comment.</p>
{% endif %}
</div>
Maybe there is a problem with my urls.py
file?
This is the url for my individual blog post:
url(r'^book/(?P<pk>\d+)$', BookDetail.as_view(), name='book-detail'),
Following the documentation mentioned in the source documentation, I included:
url(r'^book/(?P<object_id>\d+)/rate/(?P<score>[\d\-]+)$', AddRatingFromModel(), {
'app_label': 'bookBlog',
'model': 'Book',
'field_name': 'rating',
name="book_rating"),
From django-updown github:
To submit a vote just go to video/<id>/rate/(1|-1).
If you allowed users to change they're vote, they can do it with the same url.
Try following that URL directly and check if your votes are being added or not. If it is working, i guess you could just set some links to that view or something (or send some ajax requests).