PaperParser/app/models/user.py

35 lines
1.2 KiB
Python
Raw Normal View History

from sqlalchemy import Integer, false, null
2024-01-31 19:37:01 +10:00
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)
2024-03-09 23:13:04 +10:00
phone: Mapped[str] = mapped_column(nullable=True)
username: Mapped[str] = mapped_column(nullable=True)
2024-04-12 16:55:27 +10:00
description: Mapped[str] = mapped_column(nullable=True)
2024-04-12 21:41:37 +10:00
delete: Mapped[bool] = mapped_column(default=False)
2024-03-13 16:49:37 +10:00
2024-02-24 22:34:54 +10:00
collection_id = Column(Integer, ForeignKey("collection.id"))
2024-03-09 01:51:36 +10:00
collection: Mapped["Collection"] = relationship("Collection", back_populates="users")
def exist(username: str, collection):
2024-03-12 18:54:20 +10:00
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,
2024-04-12 16:55:27 +10:00
'description': self.description
2024-03-12 18:54:20 +10:00
}