71 lines
2.3 KiB
Python
71 lines
2.3 KiB
Python
|
import enum
|
||
|
from datetime import date
|
||
|
from typing import List
|
||
|
|
||
|
from sqlalchemy import Boolean, Date, Enum, ForeignKey, Integer, String
|
||
|
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||
|
|
||
|
from nupes.models import Base
|
||
|
|
||
|
|
||
|
class Bloc(Base):
|
||
|
__tablename__ = "bloc2024"
|
||
|
|
||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||
|
nom: Mapped[str] = mapped_column(String(32), unique=True)
|
||
|
couleur: Mapped[str] = mapped_column(String(7))
|
||
|
|
||
|
listes: Mapped[List["Liste"]] = relationship("Liste", back_populates="bloc")
|
||
|
|
||
|
|
||
|
class Nuance(Base):
|
||
|
__tablename__ = "nuance2024"
|
||
|
|
||
|
code: Mapped[str] = mapped_column(String(8), primary_key=True)
|
||
|
nom: Mapped[str] = mapped_column(String(32), unique=True)
|
||
|
couleur: Mapped[str] = mapped_column(String(7))
|
||
|
|
||
|
listes: Mapped[List["Liste"]] = relationship("Liste", back_populates="nuance")
|
||
|
|
||
|
|
||
|
class Liste(Base):
|
||
|
__tablename__ = "liste2024"
|
||
|
|
||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||
|
nom: Mapped[str] = mapped_column(String(256), unique=True)
|
||
|
numero: Mapped[int] = mapped_column(Integer(), unique=True)
|
||
|
nuance_id: Mapped[str] = mapped_column(ForeignKey("nuance2024.code"))
|
||
|
bloc_id: Mapped[int] = mapped_column(ForeignKey("bloc2024.id"))
|
||
|
|
||
|
nuance: Mapped[Nuance] = relationship(Nuance, back_populates="listes")
|
||
|
bloc: Mapped[Bloc] = relationship(Bloc, back_populates="listes")
|
||
|
|
||
|
|
||
|
class Candidat(Base):
|
||
|
class Genre(enum.Enum):
|
||
|
MASCULIN = "M"
|
||
|
FEMININ = "F"
|
||
|
|
||
|
class Personnalite(enum.Enum):
|
||
|
DEFAUT = ""
|
||
|
EURODEPUTE = "RPE"
|
||
|
DEPUTE = "DEP"
|
||
|
SENATEUR = "SEN"
|
||
|
MINISTRE = "MIN"
|
||
|
PRESIDENT_CONSEIL_REGIONAL = "PCR"
|
||
|
PRESIDENT_CONSEIL_DEPARTEMENTAL = "PCD"
|
||
|
MAIRE = "MAI"
|
||
|
|
||
|
__tablename__ = "candidat2024"
|
||
|
|
||
|
id: Mapped[int] = mapped_column(primary_key=True)
|
||
|
liste_id: Mapped[int] = mapped_column(ForeignKey("liste2024.id"))
|
||
|
ordre: Mapped[int] = mapped_column(Integer())
|
||
|
nom: Mapped[str] = mapped_column(String(256))
|
||
|
prenom: Mapped[str] = mapped_column(String(256))
|
||
|
sexe: Mapped[str] = mapped_column(Enum(Genre))
|
||
|
date_naissance: Mapped[date] = mapped_column(Date())
|
||
|
profession: Mapped[str] = mapped_column(String(256))
|
||
|
code_personnalite: Mapped[str] = mapped_column(Enum(Personnalite))
|
||
|
sortant: Mapped[bool] = mapped_column(Boolean())
|