from datetime import datetime from flask_sqlalchemy import SQLAlchemy from sqlalchemy import ForeignKey from sqlalchemy.orm import Mapped, mapped_column, relationship db = SQLAlchemy() class Projekt(db.Model): __tablename__ = "projekt" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) titel: Mapped[str] = mapped_column(nullable=False) beschreibung: Mapped[str] = mapped_column(nullable=False) kategorie: Mapped[str] = mapped_column(nullable=False) behoerde: Mapped[str] = mapped_column(nullable=False) kontakt_email: Mapped[str] = mapped_column(nullable=False) status: Mapped[str] = mapped_column(default="offen", nullable=False) erstellt_am: Mapped[datetime] = mapped_column(default=datetime.utcnow) bewerbungen = relationship("Bewerbung", back_populates="projekt", cascade="all, delete-orphan") class Bewerbung(db.Model): __tablename__ = "bewerbung" id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True) projekt_id: Mapped[int] = mapped_column(ForeignKey("projekt.id"), nullable=False) name: Mapped[str] = mapped_column(nullable=False) email: Mapped[str] = mapped_column(nullable=False) nachricht: Mapped[str] = mapped_column(nullable=True) erstellt_am: Mapped[datetime] = mapped_column(default=datetime.utcnow) projekt = relationship("Projekt", back_populates="bewerbungen")