Hi All, I'm finding myself creating more and more fields in a model to keep my templates clean. Since it's merely temporary calculated data, and not data to store permanently it feels like the wrong place. An example:
I have a product model (child object of an order model). The product has a 'per_price' and 'amount' field that get filled by the user. I gave the product an extra field called 'total_price' where I store 'amount * per_price' just before my view and my template come together. This way all that's needed to display an invoice is in the objects list. Calculating this in the template also doesn't seem the way. For MVC's sake I belief this belongs in the view, but then it's to late (read: there's no field on the object) to store temporary stuff. The Q: How does one relate temporary data to objects in a list, before it's rendered in a template? Thanx a lot, Gerard. Some source snippets if it's not clear: # ---- Model class Product(models.Model): per_price = models.DecimalField('Product price', max_digits=15, decimal_places=2) total_price = models.DecimalField('Calculated', max_digits=15, decimal_places=2, editable=False, null=True) amount = models.IntegerField('#', max_length=10) # ---- View def download_order(request, order_id): for p in product_list: # Calculate product totals p.total = Decimal(p.amount * p.per_price) # ---- Template {% for product in product_list %} <tr class="{% cycle 'row1' 'row2' %}"> <td>{{ product.name }}</td> <td>{{ product.description }}</td> <td>{{ product.total }}</td> -- urls = { 'fun': 'www.zonderbroodje.nl', 'tech': 'www.gp-net.nl' } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---