2024-06-08 15:10:19 +00:00
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from sqlalchemy import Float, ForeignKey, Integer, JSON, String
|
|
|
|
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
|
|
|
|
|
|
|
from nupes.models import Base
|
|
|
|
|
|
|
|
|
|
|
|
class Region(Base):
|
|
|
|
__tablename__ = "region"
|
|
|
|
|
|
|
|
code_insee: Mapped[str] = mapped_column(String(3), primary_key=True)
|
|
|
|
libelle: Mapped[str] = mapped_column(String(64), unique=True)
|
|
|
|
geometry: Mapped[dict] = mapped_column(JSON())
|
|
|
|
|
|
|
|
departements: Mapped[List["Departement"]] = relationship("Departement", back_populates="region")
|
|
|
|
|
2024-06-08 17:38:59 +00:00
|
|
|
resultats2024 = relationship("ResultatsRegion", back_populates="region")
|
|
|
|
|
2024-06-08 15:10:19 +00:00
|
|
|
|
|
|
|
class Departement(Base):
|
|
|
|
__tablename__ = "departement"
|
|
|
|
|
2024-06-09 14:47:37 +00:00
|
|
|
code_insee: Mapped[str] = mapped_column(String(3), primary_key=True)
|
2024-06-08 15:10:19 +00:00
|
|
|
libelle: Mapped[str] = mapped_column(String(64), unique=True)
|
|
|
|
region_code: Mapped[int] = mapped_column(ForeignKey("region.code_insee"))
|
|
|
|
geometry: Mapped[dict] = mapped_column(JSON())
|
|
|
|
|
|
|
|
region: Mapped[Region] = relationship(Region, back_populates="departements")
|
|
|
|
communes: Mapped[List["Commune"]] = relationship("Commune", back_populates="departement")
|
|
|
|
|
2024-06-08 17:38:59 +00:00
|
|
|
resultats2024 = relationship("ResultatsDepartement", back_populates="departement")
|
|
|
|
|
2024-06-08 15:10:19 +00:00
|
|
|
|
|
|
|
class Commune(Base):
|
|
|
|
__tablename__ = "commune"
|
|
|
|
|
|
|
|
code_insee: Mapped[str] = mapped_column(String(5), primary_key=True)
|
|
|
|
libelle: Mapped[str] = mapped_column(String(64))
|
|
|
|
departement_code: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
|
|
|
geometry: Mapped[dict] = mapped_column(JSON())
|
|
|
|
|
|
|
|
departement: Mapped[Departement] = relationship(Departement, back_populates="communes")
|
|
|
|
bureaux_vote: Mapped[List["BureauVote"]] = relationship("BureauVote", back_populates="commune")
|
|
|
|
|
2024-06-08 17:38:59 +00:00
|
|
|
resultats2024 = relationship("ResultatsCommune", back_populates="commune")
|
|
|
|
|
2024-06-08 15:10:19 +00:00
|
|
|
|
|
|
|
class Circonscription(Base):
|
|
|
|
__tablename__ = "circonscription"
|
|
|
|
|
|
|
|
id: Mapped[str] = mapped_column(String(6), primary_key=True)
|
|
|
|
departement_code: Mapped[str] = mapped_column(ForeignKey("departement.code_insee"))
|
|
|
|
numero: Mapped[int] = mapped_column(Integer())
|
|
|
|
|
|
|
|
departement: Mapped[Departement] = relationship(Departement)
|
|
|
|
bureaux_vote: Mapped[List["BureauVote"]] = relationship("BureauVote", back_populates="circonscription")
|
|
|
|
|
|
|
|
|
|
|
|
class BureauVote(Base):
|
|
|
|
__tablename__ = "bureau_vote"
|
|
|
|
|
|
|
|
id: Mapped[str] = mapped_column(String(16), primary_key=True)
|
|
|
|
commune_code: Mapped[str] = mapped_column(ForeignKey("commune.code_insee"))
|
|
|
|
code_bureau: Mapped[str] = mapped_column(String(8))
|
|
|
|
circo_code: Mapped[str] = mapped_column(ForeignKey("circonscription.id"))
|
|
|
|
libelle: Mapped[str] = mapped_column(String(256))
|
|
|
|
adresse: Mapped[str] = mapped_column(String(256), nullable=True)
|
|
|
|
geometry: Mapped[dict] = mapped_column(JSON())
|
|
|
|
|
|
|
|
commune: Mapped[Commune] = relationship(Commune, back_populates="bureaux_vote")
|
|
|
|
circonscription: Mapped[Circonscription] = relationship(Circonscription, back_populates="bureaux_vote")
|
2024-06-08 17:38:59 +00:00
|
|
|
|
|
|
|
resultats2024 = relationship("ResultatsBureauVote", back_populates="bureau_vote")
|