models.py 2.04 KB
Newer Older
Nicolas Joyard committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
# -*- coding: utf-8 -*-

from flask_sqlalchemy import SQLAlchemy


db = SQLAlchemy()


SHORT_STRING = 64
MEDIUM_STRING = 255
LARGE_STRING = 2048


class Job(db.Model):
    __tablename__ = 'jobs'

    id = db.Column(db.Integer, primary_key=True)
    nom = db.Column(db.String(MEDIUM_STRING))
    date_exec = db.Column(db.DateTime)
    url_fichier = db.Column(db.String(LARGE_STRING))
    date_fichier = db.Column(db.DateTime)
    resultat = db.Column(db.String(MEDIUM_STRING))


class Regime(db.Model):
    __tablename__ = 'regimes'

    id = db.Column(db.Integer, primary_key=True)
    nom = db.Column(db.String(MEDIUM_STRING))


class Legislature(db.Model):
    __tablename__ = 'legislatures'

    id = db.Column(db.Integer, primary_key=True)
    numero = db.Column(db.Integer)
    date_debut = db.Column(db.Date)
    date_fin = db.Column(db.Date)

    regime_id = db.Column(db.Integer, db.ForeignKey('regimes.id'))
    regime = db.relationship("Regime", back_populates="legislatures")


Regime.legislatures = db.relationship("Legislature", order_by=Legislature.id,
                                      back_populates="regime")


class Organe(db.Model):
    __tablename__ = 'organes'

    id = db.Column(db.Integer, primary_key=True)
    id_an = db.Column(db.String)
    type = db.Column(db.String(SHORT_STRING))
    libelle = db.Column(db.String(LARGE_STRING))
    libelle_court = db.Column(db.String(MEDIUM_STRING))
    abbreviation = db.Column(db.String(SHORT_STRING))
    date_debut = db.Column(db.Date)
    date_fin = db.Column(db.Date)

    regime_id = db.Column(db.Integer, db.ForeignKey('regimes.id'))
    regime = db.relationship("Regime", back_populates="organes")

    legislature_id = db.Column(db.Integer, db.ForeignKey('legislatures.id'))
    legislature = db.relationship("Legislature", back_populates="organes")


Regime.organes = db.relationship("Organe", order_by=Organe.id,
                                 back_populates="regime")
Legislature.organes = db.relationship("Organe", order_by=Organe.id,
                                      back_populates="legislature")