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
Built Distribution
File details
Details for the file attrs_sqlalchemy-0.1.0.tar.gz
.
File metadata
- Download URL: attrs_sqlalchemy-0.1.0.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cd34358b49551007e4c2b253c1c4e65c1c0d7be2a9216ca8be9a72873988d65 |
|
MD5 | 19fb0de2c223119db13c7ba9b9f2b197 |
|
BLAKE2b-256 | 3d0d7011942d531e2a6b16e003190e4427f436177600f92781349c25d598086d |
File details
Details for the file attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: attrs_sqlalchemy-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d39b4f5e5fed12f5aa9da0fc7220fc9a49b4b242ab6ce70c6b2923fb5170956 |
|
MD5 | 4a5ed525ca833ed06713426a13c435cb |
|
BLAKE2b-256 | 336b0887c62a8ec6b57e07ea0283c0ac58d272e5f16b3ad9327ecb897b975942 |