Spaces:
Runtime error
Runtime error
from sqlalchemy import create_engine, Column, Integer, String, Boolean, Date, ForeignKey, CheckConstraint | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.orm import relationship | |
from psql_database import engine, Base | |
from passlib.hash import bcrypt | |
# Define the User model | |
class User(Base): | |
__tablename__ = 'users' | |
user_id = Column(Integer, primary_key=True) | |
first_name = Column(String(50), nullable=False) | |
last_name = Column(String(50), nullable=False) | |
email = Column(String(100), nullable=False, unique=True) | |
password = Column(String(100), nullable=False) # HASHED PASSWORD | |
todos = relationship('Todo', back_populates='user') | |
def verify_password(self, plain_password): | |
return bcrypt.verify(plain_password, self.password) | |
# Define the Todo model | |
class Todo(Base): | |
__tablename__ = 'todos' | |
todo_id = Column(Integer, primary_key=True) | |
user_id = Column(Integer, ForeignKey('users.user_id'), nullable=False) | |
task_name = Column(String(100), nullable=False) | |
task_description = Column(String) | |
priority = Column(Integer, CheckConstraint('priority >= 1 AND priority <= 3', name="priority should be either 1 or 2 or 3"), nullable=False) # 1: high, 2: medium, 3: low | |
category = Column(String(50)) | |
due_date = Column(Date, nullable=False) | |
status = Column(Boolean, default=False) | |
user = relationship('User', back_populates='todos') | |
# Create the tables | |
def create_database_tables(): | |
return Base.metadata.create_all(bind=engine) | |