File size: 1,156 Bytes
bb6d7b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""
Model for users of the application.
"""
from sqlalchemy import Column, String, Boolean
from sqlalchemy.orm import relationship
from typing import List

from src.models.base import BaseModel

class User(BaseModel):
    """
    User model for authentication and authorization.
    """
    __tablename__ = "users"
    
    username = Column(String(50), unique=True, index=True, nullable=False)
    email = Column(String(100), unique=True, index=True, nullable=False)
    full_name = Column(String(100))
    hashed_password = Column(String(100), nullable=False)
    is_active = Column(Boolean, default=True)
    is_superuser = Column(Boolean, default=False)
    avatar_url = Column(String(255), nullable=True)
    bio = Column(String, nullable=True)
    last_login = Column(String(255), nullable=True)
    
    # Relationships
    searches = relationship("SearchHistory", back_populates="user")
    saved_searches = relationship("SavedSearch", back_populates="user")
    subscriptions = relationship("UserSubscription", back_populates="user")
    
    def __repr__(self):
        return f"<User(id={self.id}, username={self.username}, email={self.email})>"