From b3d92558fcfc21e72e94b129eab6e266fda87cfa Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 7 Oct 2026 14:55:42 +0200 Subject: [PATCH] fix: correction de l'indentation Python dans models.py provoquant le crash du backend --- backend/models.py | 52 ++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/backend/models.py b/backend/models.py index a3af3a6..91dcc2a 100644 --- a/backend/models.py +++ b/backend/models.py @@ -1,60 +1,44 @@ -from sqlalchemy import Column, Integer, String, Boolean, DateTime, ForeignKey, Text +from sqlalchemy import Column, Integer, String, Boolean, ForeignKey, DateTime, Float from sqlalchemy.orm import relationship from datetime import datetime, timezone from .database import Base -from sqlalchemy import Float, DateTime -from datetime import datetime, timezone class User(Base): __tablename__ = "users" - id = Column(Integer, primary_key=True, index=True) - email = Column(String, unique=True, index=True, nullable=False) - username = Column(String, unique=True, index=True, nullable=False) - hashed_password = Column(String, nullable=False) - totp_secret = Column(String, nullable=False) + email = Column(String, unique=True, index=True) + username = Column(String, unique=True, index=True) + hashed_password = Column(String) + totp_secret = Column(String) is_admin = Column(Boolean, default=False) - - # Relation : Un utilisateur peut avoir plusieurs projets - projects = relationship("Project", back_populates="owner", cascade="all, delete-orphan") - + projects = relationship("Project", back_populates="owner") class Project(Base): __tablename__ = "projects" - id = Column(Integer, primary_key=True, index=True) - title = Column(String, nullable=False) + title = Column(String, index=True) created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) is_pinned = Column(Boolean, default=False) - user_id = Column(Integer, ForeignKey("users.id"), nullable=False) - - # Relations + user_id = Column(Integer, ForeignKey("users.id")) owner = relationship("User", back_populates="projects") messages = relationship("Message", back_populates="project", cascade="all, delete-orphan") - class Message(Base): __tablename__ = "messages" - id = Column(Integer, primary_key=True, index=True) - role = Column(String, nullable=False) # Ex: 'user', 'assistant', 'worker_1', 'system' - content = Column(Text, nullable=False) + role = Column(String) + content = Column(String) created_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) - project_id = Column(Integer, ForeignKey("projects.id"), nullable=False) - - # Relation + project_id = Column(Integer, ForeignKey("projects.id")) project = relationship("Project", back_populates="messages") class SystemSettings(Base): __tablename__ = "system_settings" - id = Column(Integer, primary_key=True, index=True) - # Serveur Mail (Obligatoire) smtp_host = Column(String, nullable=False) smtp_port = Column(Integer, nullable=False) smtp_user = Column(String, nullable=False) smtp_password = Column(String, nullable=False) - # Clés API (Optionnelles) openrouter_api_key = Column(String, nullable=True) openrouter_management_key = Column(String, nullable=True) groq_api_key = Column(String, nullable=True) @@ -65,25 +49,23 @@ class SystemSettings(Base): cloudflare_api_token = Column(String, nullable=True) huggingface_api_key = Column(String, nullable=True) - class AIModel(Base): +class AIModel(Base): """Stocke la liste des modèles extraits depuis les fournisseurs.""" __tablename__ = "ai_models" - id = Column(Integer, primary_key=True, index=True) - provider = Column(String, index=True) # ex: openrouter, groq - model_id = Column(String, unique=True, index=True) # ex: google/gemini-1.5-pro + provider = Column(String, index=True) + model_id = Column(String, unique=True, index=True) name = Column(String) context_length = Column(Integer) - pricing_prompt = Column(Float) # Coût pour 1M tokens + pricing_prompt = Column(Float) pricing_completion = Column(Float) last_updated = Column(DateTime, default=lambda: datetime.now(timezone.utc)) class FinancialLog(Base): """Suivi financier par fournisseur.""" __tablename__ = "financial_logs" - id = Column(Integer, primary_key=True, index=True) provider = Column(String, index=True) - balance = Column(Float) # Crédit restant - total_usage = Column(Float) # Consommation totale + balance = Column(Float) + total_usage = Column(Float) checked_at = Column(DateTime, default=lambda: datetime.now(timezone.utc)) \ No newline at end of file