On Sep 25, 4:33 am, Gerard Petersen <[EMAIL PROTECTED]> wrote: > 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?
In addition to what has already been mentioned, it is also handy to define convenience functions on your model classes that return information like this. So your model could be given a total_price() member function that calculates it based upon member data. These convenience functions are easily accessed in the template. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---