Add dunder-methods to SQLAlchemy models with attrs
Project description
Use attrs to add __repr__, __eq__, __cmp__, and __hash__ methods according to the fields on a SQLAlchemy model class.
from attrs_sqlalchemy import attrs_sqlalchemy
@attrs_sqlalchemy
class MyModel(Base):
__tablename__ = 'mymodel'
id = sa.Column(Integer, primary_key=True)
text = sa.Column(sa.String)
instance = MyModel(id=1, text='hello')
same_data = MyModel(id=1, text='hello')
same_pk = MyModel(id=1, text='world')
assert instance == same_data
assert instance != same_pk
assert repr(instance) == "MyModel(id=1, text='hello')"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
attrs_sqlalchemy-0.1.0.tar.gz
(3.0 kB
view hashes)
Built Distribution
Close
Hashes for attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d39b4f5e5fed12f5aa9da0fc7220fc9a49b4b242ab6ce70c6b2923fb5170956 |
|
MD5 | 4a5ed525ca833ed06713426a13c435cb |
|
BLAKE2b-256 | 336b0887c62a8ec6b57e07ea0283c0ac58d272e5f16b3ad9327ecb897b975942 |