Looks like I should have accounted for negative numbers, and thousands
separators. I believe the thousands separator is region specific,
which I am not handling here.

---
class Money(types.UserDefinedType):

    def get_col_spec(self):
        return 'money'

    def result_processor(self, dialect, coltype):
        def process(value):
            # Strip off the currency symbol
            if value.startswith('-'):
                trimpoint = 2
                sign = '-'
            else:
                trimpoint = 1
                sign = ''

            return Decimal(sign + value[trimpoint:].replace(',',''))
        return process

On Dec 27, 11:39 am, dgardner <davidgardne...@gmail.com> wrote:
> Quick hack, figured I would share since there seemed to be other
> people asking about it.
>
> I couldn't get it to work with "autoload=True" for table reflection.
>
> ---
>
> from sqlalchemy import types
> from decimal import Decimal
>
> class Money(types.UserDefinedType):
>
>     def get_col_spec(self):
>         return 'money'
>
>     def result_processor(self, dialect, coltype):
>         def process(value):
>             # Strip off the currency symbol
>             return Decimal(value[1:])
>         return process

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to