from sqlalchemy import Integer, false, null from sqlalchemy.schema import ( Column, ForeignKey, ) from sqlalchemy.orm import Mapped, mapped_column, relationship from app.extensions import db class User(db.Model): id: Mapped[int] = mapped_column(primary_key=True) first_name: Mapped[str] = mapped_column(nullable=True) last_name: Mapped[str] = mapped_column(nullable=True) phone: Mapped[str] = mapped_column(nullable=True) username: Mapped[str] = mapped_column(nullable=True) description: Mapped[str] = mapped_column(nullable=True) delete: Mapped[bool] = mapped_column(default=False) collection_id = Column(Integer, ForeignKey("collection.id")) collection: Mapped["Collection"] = relationship("Collection", back_populates="users") def exist(username: str, collection): return not User.query.filter_by(username=username, collection=collection).first() is None def to_dict(self): return { 'id': self.id, 'first_name': self.first_name, 'last_name': self.last_name, 'phone': self.phone, 'username': self.username, 'description': self.description }