
    Ii=                     ~    S SK J r   S SKr " S S5      r\R                  R                  \SSS9S 5       rS	rS
 rS r	g)    )datetimeNc                       \ rS rSrSr\R                  " \R                  \R                  SS9r
\R                  " \R                  \R                  SS9rSrg)	Timestamp   a  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nullable N)__name__
__module____qualname____firstlineno____doc__saColumnDateTimer   utcnowcreatedupdated__static_attributes__r	       =/venv/lib/python3.13/site-packages/sqlalchemy_utils/models.pyr   r      s=    $ iiX__uMGiiX__uMGr   r   before_updateT)	propagatec                 8    [         R                  " 5       Ul        g )N)r   r   r   )mapper
connectiontargets      r   timestamp_before_updater      s     __&FNr   z<not loaded>c                    [         R                  " U 5      n/ nU(       d$  UR                  R                  R	                  5       nU H^  nUR
                  U   R                  nXBR                  ;   a  [        nO[        U5      nUR                  SR                  XE45      5        M`     SR                  U R                  R                  SR                  U5      5      $ )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_methodr3   '   s    JJtEK%%**,C --.. #EKE388SL12  ??4>>22DIIk4JKKr   c                  v   ^  [        T 5      S:X  a"  [        T S   5      (       a  T S   nS Ul        U$ U 4S jnU$ )at  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                     [        U S S9$ N)r.   r3   )r-   s    r   <lambda>generic_repr.<locals>.<lambda>W   s    ';D'Nr   c                    > U4S jU l         U $ )Nc                    > [        U TS9$ r7   r8   )r-   r.   s    r   r9   1generic_repr.<locals>.decorator.<locals>.<lambda>[   s    (<)r   )__repr__)clsr.   s    r   	decoratorgeneric_repr.<locals>.decoratorZ   s    CL Jr   )lencallabler>   )r.   r   r@   s   `  r   generic_reprrD   7   sA    < 6{aHVAY//N	 r   )
r   
sqlalchemyr   r   eventlistens_forr   r'   r3   rD   r	   r   r   <module>rH      sT     N N. iDA' B' !L )r   