title: Calculating total cost and adding sales tax to shopping cart
body: <p>I am creating a basic shopping cart application, I can get in my cart all of the items to populate with the quantity and cost, but I am trying to find a way thats I can create a total cost, and adding sales tax on top of that. Clearly the total line is the issue, but I am not sure what I could do to populate price and quantity for all products and multiply them together.</p>
  
  <pre><code>{% for addtocart in userCart %}
    &lt;li&gt;Quantity:{{addtocart.quantity}} &lt;a href="/products/{{addtocart.product.id}}"&gt;{{addtocart.product.prodName}}&lt;/a&gt; ${{addtocart.product.prodPrice}}(&lt;a
  href=/delItem/{{addtocart.id}}&gt;Remove&lt;/a&gt;)&lt;br&gt;
  {% endfor %}
  &lt;/ul&gt;
  {% else %}
  &lt;p&gt; No products available &lt;/p&gt;
  {% endif %}
  ***&lt;p&gt;Total: {{addtocart.quantity}}"x"{{addtocart.product.prodPrice}}***
  </code></pre>
  
  <p>views.py</p>
  
  <pre><code>def addtocart(request, prod_id):
          if (request.method == 'POST'):
                  form = CartForm(request.POST)
                  if form.is_valid():
                          newComment = form.save()
                          newComment.session = request.session.session_key[:20]
                          newComment.save()
                          return HttpResponseRedirect('/products/' + str(newComment.product.id))
          else:
                  form = CartForm( {'name':'Your Name', 'session':'message', 'product':prod_id} )
  
          return render_to_response('Products/comment.html', {'form': form, 'prod_id': prod_id})
  
  def userHistory(request):
          userCart = Cart.objects.filter(session = request.session.session_key[:20])
          return render_to_response('Products/history.html', {'userCart':userCart})
  </code></pre>
  
  <p>models.py</p>
  
  <pre><code>from django.db import models
  from django.forms import ModelForm
  
  # Create your models here.
  class prod(models.Model):
          prodName = models.CharField(max_length=100)
          prodDesc = models.TextField()
          prodPrice = models.FloatField()
          prodImage = models.ImageField(upload_to="userimages/")
          def __unicode__(self):
                  return self.prodName
  
  class Cart(models.Model):
          session = models.CharField(max_length=100)
          product = models.ForeignKey('prod')
          quantity = models.IntegerField()
  
          def __unicode__(self):
                  return self.name
  
  class CartForm(ModelForm):
          class Meta:
                  model = Cart
                  exclude = ('session')
  </code></pre>