[Answer]-Django template tag / jquery for- iteration?

1👍

A div element does not have a value attribute. Try using a hidden input element. Something like this:

<table>
    {% for result in mylist %}
        <tr><td><input type='hidden' class='hidden_score' value='{{ result.rating.score }}'></input><div class="raty"></div></td></tr>
     {% endfor %}
</table>

And then in your script:

$.each($('.hidden_score'), function( index, value ) {
    var myval = $(this).val();
    $(this).parent().find( '.raty').raty({ readOnly:true, score:myval});
});

So, for each of elements having a class of hidden_score, you will get their value make a “raty” with the elemens belonging to the parent of each element (so they are siblings) with the correct score.

Leave a comment