title: Django - Rating System View & Template
body: <p>I have a content that I'd like to rate on multiple criteria.<br>
  Imagine this kind of model:</p>
  
  <pre><code>class Content(models.Model):
    name = models.CharField(max_length=50)
  
  class Criterion(models.Model):
    name = models.CharField(max_length=50)
    content = models.ForeignKey(Content)
  
  class ContRate(models.Model):
    user = models.ForeignKey(User, help_text="Who rated ?")
    crit = models.ForeignKey(Criterion)
    rate = models.DecimalField()
  </code></pre>
  
  <p>The user has a page displaying the content.<br>
  From this page, he can also rate the content on the criteria set</p>
  
  <p><img src="https://i.stack.imgur.com/xXhKw.png" alt="Rating Criteria"></p>
  
  <p>The rating will be done with Ajax.<br>
  Now I'm trying to implement the view &amp; the template</p>
  
  <p><strong>view.py</strong></p>
  
  <pre><code>#...
  def viewcont(request, content_id):
    """The user can view a content &amp; rate it"""
    content = get_object_or_404(Content, pk=content_id)
    RateFormSet = modelformset_factory(ContRate)
    formset = RateFormSet(queryset=ContRate.objects.filter(content=content, user=request.user))
    objs = {
      'content': content,
      'forms': formset,
    }
    return render_to_response('content/content_detail.html', objs
    , context_instance=RequestContext(request)
    )
  #...
  </code></pre>
  
  <p><strong>content_detail.html</strong></p>
  
  <pre><code>&lt;!-- ... --&gt;
  &lt;div id="rating"&gt;
    &lt;ul&gt;
  {% for crit in content.crit_set.all %}
      &lt;li&gt;
        {{ crit }}
        &lt;div class="rateit"
          data-rateit-value="the_actual_rating_if_already_there"
          data-rateit-ispreset="true"
          crit-id="{{ crit.id }}"&gt;&lt;/div&gt;
      &lt;/li&gt;
  {% endfor %}
    &lt;/ul&gt;
  &lt;/div&gt;
  &lt;!-- ... --&gt;
  </code></pre>
  
  <p>Now how can I use the <code>forms</code> formset to display the actual rates ?<br>
  And how can I draw an empty form to be posted by Ajax from any clicked star ?<br>
  (I know the javascript/jQuery part)</p>