In web2py SQLFORM grid, numbers are shown unformatted and left-aligned. It will be better if the numbers or money values are currency formatted, to make it easier to read. And better yet if those numbers right-aligned in the grid / table. We can use represent in models to do the job, like:
At some point in doing web application using web2py/Python I need to show numbers in money formatted string. Seems a little problem easy to handle, at first. After searching about money at Python Package Index then I know it was quite complex matter involved many things…
Anyway, the money format for my purpose it is enough to use simple function to convert number to money formatted string, and I use “moneyfmt” recipe I found at Python Docs, modified it a little, set places=0 as default, add condition if places == 0 to automatically set dp='' if places=0, so I don’t have to set “dp” parameter when I need to change the number of “places”.
We can fill a field based on another field, for example to calculate/compute a total value.
return request.vars.in_time + request.vars.duration ##
Field('duration', 'integer'), Field('end_time','datetime', compute = _compute))