
I want to program to calculate sum of user sleclecion of options with checkbox.
Pls help me how to keep away from this suffer.
I summarize what I want to do in my attached ppt file.
How can I code for this in my viws.py & models.py each?
#Product&Choice Model - models.py
class Product(models.Model):
title = models.CharField(max_length=120)
description = models.TextField(null=True, blank=True)
price = models.DecimalField(decimal_places=0, max_digits=100, default=10000)
class Choice(models.Model):
product = models.ForeignKey(Product)
name = models.CharField(max_length=255)
price = models.DecimalField(decimal_places=0, max_digits=100, default=0)
# single.html
<p>Your Product Price : {{ product.price }}$</p><hr/>
{% for item in product.choice_set.all %}
<form method='POST' action=''>{% csrf_token %}<input type='checkbox' value='{{
item.id }}' name='choice'> {{
item.name }} : {{ item.price }}$ <br/>
{% endfor %}
<input type='submit' value='submit'>
</form><hr/>
~~