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')"
Release files for attrs-sqlalchemy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| attrs_sqlalchemy-0.1.0.tar.gz | 3.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 8.1 kB
Release files / attrs_sqlalchemy-0.1.0.tar.gz
| Download URL | attrs_sqlalchemy-0.1.0.tar.gz |
|---|---|
| Size | 3.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3cd34358b49551007e4c2b253c1c4e65c1c0d7be2a9216ca8be9a72873988d65
|
|
BLAKE2b-256 checksum How to use checksums |
3d0d7011942d531e2a6b16e003190e4427f436177600f92781349c25d598086d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl
| Download URL | attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5d39b4f5e5fed12f5aa9da0fc7220fc9a49b4b242ab6ce70c6b2923fb5170956
|
|
BLAKE2b-256 checksum How to use checksums |
336b0887c62a8ec6b57e07ea0283c0ac58d272e5f16b3ad9327ecb897b975942
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |