ORM properties can be named differently to the underlying columns:

https://docs.sqlalchemy.org/en/13/orm/mapping_columns.html#naming-columns-distinctly-from-attribute-names

You could also create a TypeDecorator which converts to and from the
pandas datatypes as the values are retrieved from and saved back to
the database:

https://docs.sqlalchemy.org/en/13/core/custom_types.html#augmenting-existing-types

Hope that helps,

Simon

On Fri, Sep 13, 2019 at 3:46 PM Gary L <[email protected]> wrote:
>
> I have a declarative model as below
>
>
> class User(Base):
>     __tablename__ = 'users'
>     __table_args__ = {
>         'schema':'internal',
>         'extend_existing': True,
>         'mustexist': True
>     }
>
>
> The table has a column named 'registration_date'. Since I am working with 
> pandas I'd like to wrap this in a pandas timestamp when using it.
> Ideally something like this would be possible:
>
> def registration_date(self):
>     return pd.to_datetime(self.registration_date)
>
> But this causes a name collision between the mapped column and this new 
> method so trying to query the column via User.registration_date will not work 
> as this returns the method instead of the queryable attribute. The natural 
> solution would be to rename the method but that isn't ideal as I want all my 
> users to have the same idea of a registration date. Is this possible in 
> sqlalchemy?
>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/b7cd73e2-a69b-44e9-b2fa-bdc302c4b7f6%40googlegroups.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/CAFHwexfbmj%3D9zmemNPwXJ5%3DhRuCLRTLP2eP6zxvfqo45EYS6rA%40mail.gmail.com.

Reply via email to