Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for @declared_attr sqlalchemy decorator #23

Open
bitphage opened this issue Apr 29, 2021 · 0 comments
Open

Add support for @declared_attr sqlalchemy decorator #23

bitphage opened this issue Apr 29, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@bitphage
Copy link

bitphage commented Apr 29, 2021

SQLAlchemy has @declared_attr decorator which adds declarative fields for "base" models. It would be nice to allow to keep @declared_attr methods close to class attributes like this:

class Foo:
    field = Column(String(45), nullable=False)
    other_field = Column(String(45), nullable=False)
    more_field = Column(String(45), nullable=False)

    @declared_attr
    def client_id(cls):
        return Column(String(256), ForeignKey("UserModel.client_id"), nullable=False)

    # other stuff
    @property
    def timestamp(self) -> Timestamp_ms:
        return self.last_update_timestamp

https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/api.html#sqlalchemy.ext.declarative.declared_attr

@bitphage bitphage added the enhancement New feature or request label Apr 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant