30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
from sqlalchemy import Column, String, Integer, Boolean, DateTime, ForeignKey, Enum
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
from core.database import Base
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
|
first_name = Column(String(50), nullable=False)
|
|
last_name = Column(String(50), nullable=False)
|
|
email = Column(String(100), unique=True, nullable=False, index=True)
|
|
password = Column(String, nullable=False)
|
|
role = Column(Enum('student', 'teacher', 'admin', name='user_roles'), nullable=False)
|
|
phone_number = Column(String(20))
|
|
address = Column(String(200))
|
|
date_of_birth = Column(DateTime)
|
|
profile_picture = Column(String)
|
|
is_active = Column(Boolean, default=True)
|
|
last_login = Column(DateTime)
|
|
|
|
created_at = Column(DateTime, default=func.now())
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
courses = relationship("Course", secondary="user_courses", back_populates="users")
|
|
assignments = relationship("Assignment", back_populates="user")
|
|
grades = relationship("Grade", back_populates="user")
|
|
attendance = relationship("Attendance", back_populates="user") |