On Tue, Sep 26, 2017 at 3:41 PM, Samer Atiani <sati...@gmail.com> wrote:
> Hello all,
>
> I'm trying to implement a solution whereby I store Money amounts in the
> database as both currency and amounts. The best I've come up with is in this
> gist:
>
> https://gist.github.com/satiani/b20d7e81e48a041d241d61e9aab61be2
>
> It's important for me to be able to do comparisons and aggregate functions
> on MoneyComposite columns and I've managed to get it working somewhat with a
> function like func.sum_money() (as can be seen in line 162 in the gist).
>
> However, anything more complex than a simple straightforward sum of one
> column fails. I tried fiddling around with MoneyComparator (line 53) and
> changing how the type engine works (line 110), but I could not get a working
> solution.
>
> I'd appreciate any help or pointers to help me make this into a more robust
> solution.

You might want to look into my series of blog posts about hybrids
which specifically happen to use money + currency types:
http://techspot.zzzeek.org/2011/10/21/hybrids-and-value-agnostic-types/
   This not the only way to do it but I've done something similar in
production and we did a fair amount of currency math.   However it
does store balances in a fixed currency, which I know is not what you
want.  You'd need to wire in the currency persistence from your
composite into it.



>
> Best,
> Samer
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to