fastapi-svelte-template/backend/todo/models/users.py

25 lines
1.0 KiB
Python
Raw Permalink Normal View History

"""This module defines the SQL data model for users."""
2023-05-31 16:37:56 +01:00
from sqlalchemy import Column, Integer, String, DateTime, Boolean
from sqlalchemy.sql.functions import now
from sqlalchemy.orm import relationship
from todo.database.engine import Base
class User(Base):
"""Model for the users table."""
__tablename__ = "users"
id = Column('id', Integer, primary_key=True, autoincrement=True, index=True)
email = Column('email', String, unique=True, nullable=False, index=True)
password = Column('password', String, nullable=False)
created = Column('created', DateTime(timezone=True), nullable=False, server_default=now())
updated = Column('updated', DateTime(timezone=True), nullable=False, server_default=now(), onupdate=now())
first_name = Column('first_name', String, nullable=False)
last_name = Column('last_name', String, nullable=False, index=True)
2023-05-31 16:37:56 +01:00
is_admin = Column('is_admin', Boolean, nullable=False, default=False, index=True)
todo_items = relationship("TodoItem", back_populates="user", uselist=True, cascade="all, delete")