28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
"""
|
|
User model for the PostgreSQL database
|
|
"""
|
|
from sqlalchemy import Column, String, Boolean, DateTime, func, UUID
|
|
from sqlalchemy.orm import relationship
|
|
import uuid
|
|
from app import Base
|
|
|
|
class User(Base):
|
|
"""User model representing a user in the system"""
|
|
__tablename__ = 'users'
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
username = Column(String(50), unique=True, nullable=False, index=True)
|
|
email = Column(String(100), unique=True, nullable=False, index=True)
|
|
password_hash = Column(String(100), nullable=False)
|
|
first_name = Column(String(50))
|
|
last_name = Column(String(50))
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, default=func.now())
|
|
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
|
|
|
|
# Relationships
|
|
posts = relationship("Post", back_populates="user", cascade="all, delete-orphan")
|
|
|
|
def __repr__(self):
|
|
return f"<User(username='{self.username}', email='{self.email}')>"
|