Hi,

You probably need to use javascript to make the total price auto-update 
when you check or uncheck each box. Check out jQuery if you haven't.

Once you have that, then, yes, you'll want to re-calculate the price in 
django to be sure it's correct.

You could create an Order or Cart model that stores which (or how many of 
each) items have been select, and maybe the total price too.

Collin

On Sunday, January 4, 2015 12:55:02 AM UTC-5, rdyact wrote:
>
>
> <https://lh3.googleusercontent.com/-CmnYqbBB-ws/VKjVXOH24II/AAAAAAAAHQw/0zYR1Des11Y/s1600/checkbox%2Boption.png>
> 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/>
> ~~
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b6b494e4-8fea-4577-8ebf-efa4fd8382c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to