Ajout données de géométrie administrative
This commit is contained in:
66
nupes/models/geographie.py
Normal file
66
nupes/models/geographie.py
Normal file
@ -0,0 +1,66 @@
|
||||
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")
|
||||
|
||||
|
||||
class Departement(Base):
|
||||
__tablename__ = "departement"
|
||||
|
||||
code_insee: Mapped[str] = mapped_column(String(2), primary_key=True)
|
||||
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")
|
||||
|
||||
|
||||
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")
|
||||
|
||||
|
||||
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")
|
Reference in New Issue
Block a user