
    j=                         d dl m Z  d dlZ G d d          Zej                            edd          d             Zd	Zd
 Zd Z	dS )    )datetimeNc                       e Zd ZdZ ej        ej        ej        d          Z	 ej        ej        ej        d          Z
dS )	Timestampa  Adds `created` and `updated` columns to a derived declarative model.

    The `created` column is handled through a default and the `updated`
    column is handled through a `before_update` event that propagates
    for all derived declarative models.

    ::


        import sqlalchemy as sa
        from sqlalchemy_utils import Timestamp


        class SomeModel(Base, Timestamp):
            __tablename__ = 'somemodel'
            id = sa.Column(sa.Integer, primary_key=True)
    F)defaultnullableN)__name__
__module____qualname____doc__saColumnDateTimer   utcnowcreatedupdated     a/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/sqlalchemy_utils/models.pyr   r      sR         $ biX_uMMMGbiX_uMMMGGGr   r   before_updateT)	propagatec                 6    t          j                    |_        d S )N)r   r   r   )mapper
connectiontargets      r   timestamp_before_updater      s     _&&FNNNr   z<not loaded>c                    t          j        |           }g }|s|j        j                                        }|D ]^}|j        |         j        }||j        v rt          }nt          |          }|
                    d                    ||f                     _d                    | j        j        d                    |                    S )N=z{}({})z, )r   inspectr   columnskeysattrsloaded_valueunloadedNOT_LOADED_REPRreprappendjoinformat	__class__r   )selffieldsstatefield_reprskeyvalues         r   _generic_repr_methodr0   '   s    JtEK -%**,, 3 3C -%.  #EEKKE388S%L112222??4>2DIIk4J4JKKKr   c                       t                     dk    r't           d                   r d         }d |_        |S  fd}|S )a  Adds generic ``__repr__()`` method to a declarative SQLAlchemy model.

    In case if some fields are not loaded from a database, it doesn't
    force their loading and instead repesents them as ``<not loaded>``.

    In addition, user can provide field names as arguments to the decorator
    to specify what fields should present in the string representation
    and in what order.

    Example::


        import sqlalchemy as sa
        from sqlalchemy_utils import generic_repr


        @generic_repr
        class MyModel(Base):
            __tablename__ = 'mymodel'
            id = sa.Column(sa.Integer, primary_key=True)
            name = sa.Column(sa.String)
            category = sa.Column(sa.String)

        session.add(MyModel(name='Foo', category='Bar'))
        session.commit()
        foo = session.query(MyModel).options(sa.orm.defer('category')).one(s)

        assert repr(foo) == 'MyModel(id=1, name='Foo', category=<not loaded>)'
       r   c                 $    t          | d           S N)r+   r0   )r*   s    r   <lambda>zgeneric_repr.<locals>.<lambda>W   s    ';D'N'N'N r   c                     fd| _         | S )Nc                 &    t          |           S r4   r5   )r*   r+   s    r   r6   z1generic_repr.<locals>.decorator.<locals>.<lambda>[   s    (<) ) ) r   )__repr__)clsr+   s    r   	decoratorzgeneric_repr.<locals>.decoratorZ   s"       CL Jr   )lencallabler9   )r+   r   r;   s   `  r   generic_reprr>   7   s`    < 6{{aHVAY//NN	 	 	 	 	 r   )
r   
sqlalchemyr   r   eventlistens_forr   r$   r0   r>   r   r   r   <module>rB      s             N N N N N N N N. iDAA' ' BA' !L L L ) ) ) ) )r   