Wednesday, December 26, 2012

Re: Django comments customization issue

Hi donarb,

Thanks for your reply. It worked after changing the input tags names as you mentioned.

And also, thanks for mentioned about BR tags as well.

Thanks


On Wednesday, 26 December 2012 20:06:15 UTC, donarb wrote:
On Wednesday, December 26, 2012 11:43:47 AM UTC-8, sri wrote:

Hi, I am trying to learn django comments customization by adding an integer field to the comments framework. My Model looks like below

class CommentWithRating(Comment): rating = models.IntegerField(name='rating')

And i am trying to display the value in the rating field by using the jquery star, but it is displaying all the stars in one comment. Please check the link to see how the comments are displayed. http://imgur.com/43CUU [1]

The code i am using in my template is as below.

        <div class="comments">              {% load comments %}              </br>              <h4> Add Your Comments Here / Rate : </h4></br>              {% render_comment_form for party_details %}              {% get_comment_count for party_details as comment_count %}              <p> <b> Customer Reviews</b>( {{ comment_count }} comments have been posted.)</p>              </br>              {% get_comment_list for party_details as comment_list %}              {% for comment in comment_list %}                  <div class="ind_comment">                      <p><u>Posted by: <i>{{ comment.user_name }}</i> on {{ comment.submit_date }}</u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rating:                                          <div class="comment_star">                              {% for i in loop_times %}                                  {% if i == comment.rating %}                                      <input name="star" type="radio" class="star" checked="checked" disabled="disabled"/>                                  {% else %}                                      <input name="star" type="radio" class="star" disabled="disabled"/>                                  {% endif %}                              {% endfor %}                              {{ comment.rating }}                          </div>                      </p>                      <p>Comment: {{ comment.comment }}</p>                  </div>              {% endfor %}          </div>  

I am working on Django 1.4.1 version and http://www.fyneworks.com/jquery/star-rating/#tab-Overview[2] (for jquery stars). loop_times in the template is a range from 1 to 5, which is passed from the view.

Can anyone help with why the ratings are all displayed in one place when i use jquery star.

Thanks in advance.



It's most likely because your input items all have the same name 'star'. You should use an index in the loop to make the names unique for each of the comments. Something like:

{% if i == comment.rating %}
    <input name="star{{ forloop.parentloop.counter }}" type="radio" class="star" checked=="checked" disabled="disabled"/>
{% else %}
    <input name="star{{ forloop.parentloop.counter }}" type="radio" class="star" disabled="disabled"/>
{% endif %}

Note you have to use parentloop because your loop is nested.

Also as an FYI, your 'br' tags are coded wrong, they should be '<br />'.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/NZICD7DewckJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment