Search code examples
djangorating-systemtemplatetags

Using Templatetags with Django Ratings


I am using dcramer's djangoratings to try to implement a ratings system, but am having problems using some of the templatetags that he mentions.

My model is:

class Thing(models.Model):
    rating = RatingField(range=3)

I am trying to use the templatetags included in the package to get the user's vote as described here:

rating_by_request

Retrieves the Vote cast by a user on a particular object and stores it in a context variable. If the user has not voted, the context variable will be 0:

{% rating_by_request request on instance.field as vote %}

rating_by_user

Retrieves the Vote cast by a user on a particular object and stores it in a context variable. If the user has not voted, the context variable will be 0:

{% rating_by_user user on instance.field as vote %}

But may be using them incorrectly,

{% rating_by_user user on Thing.rating as vote %}
{{ vote }}
{% rating_by_request request on Thing.rating as rate %}
{{ rate }}

.. Because {{ vote }} and {{ rate }} don't return any values. How do I use these tags to get the objects as described? Thank you!


Solution

  • Do you set in view context thing or Thing variable? If in view 'thing': Thing.objects.get(...)

    {% rating_by_user user on thing.rating as vote %}
    {{ vote }}
    {% rating_by_request request on thing.rating as rate %}
    {{ rate }}