From 3fb522534cff61576ac58ae466a2752585b8c44e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 1 Jun 2020 19:45:15 +0200 Subject: setting up the database... --- cli/app/sql/models/page.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'cli/app/sql/models/page.py') diff --git a/cli/app/sql/models/page.py b/cli/app/sql/models/page.py index 1362bb3..bad5568 100644 --- a/cli/app/sql/models/page.py +++ b/cli/app/sql/models/page.py @@ -1,15 +1,17 @@ -from sqlalchemy import create_engine, Table, Column, Text, String, Integer, DateTime, JSON +from sqlalchemy import create_engine, Table, Column, Text, String, Integer, DateTime, JSON, ForeignKey +from sqlalchemy.orm import relationship import sqlalchemy.sql.functions as func from sqlalchemy_utc import UtcDateTime, utcnow from wtforms_alchemy import ModelForm from app.sql.common import db, Base, Session +# from app.sql.models.graph import Graph from app.settings import app_cfg class Page(Base): """Table for storing references to pages""" - __tablename__ = 'pages' + __tablename__ = 'page' id = Column(Integer, primary_key=True) graph_id = Column(Integer, ForeignKey('graph.id'), nullable=True) path = Column(String(64, convert_unicode=True), nullable=False) @@ -17,9 +19,9 @@ class Page(Base): description = Column(Text(convert_unicode=True), nullable=False) settings = Column(JSON, default={}, nullable=True) created_at = Column(UtcDateTime(), default=utcnow()) - updated_at = Column(UtcDateTime(), default=utcnow()) + updated_at = Column(UtcDateTime(), onupdate=utcnow()) - tiles = relationship("Tile", secondary="tiles", lazy='dynamic') + # tiles = relationship("Tile", lazy='dynamic') def toJSON(self): return { @@ -33,9 +35,14 @@ class Page(Base): 'updated_at': self.updated_at, } -class PageForm(ModelForm): - class Meta: - model = Page - exclude = ['graph_id', 'settings', 'created_at', 'updated_at'] - def get_session(): - return Session() + def toFullJSON(self): + data = self.toJSON() + data['tiles'] = [ tile.toJSON() for tile in self.tiles ] + return data + +# class PageForm(ModelForm): +# class Meta: +# model = Page +# exclude = ['graph_id', 'settings', 'created_at', 'updated_at'] +# def get_session(): +# return Session() -- cgit v1.2.3-70-g09d2