Frage

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!

War es hilfreich?

Lösung

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 }}

Andere Tipps

{{}} this tag is used for display the information. if you want to get information from user you should try something like in .html file

<form action="address of your view" method="get">
{%csrf_token%}
<input type="text" name="vote"/ >
<input type="submit" value="ok">
</form>

in your view

vote_val=request.GET.get('vote','default_value')

now vote is stored in vote_val

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top