diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2020-06-01 19:45:15 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2020-06-01 19:45:15 +0200 |
| commit | 3fb522534cff61576ac58ae466a2752585b8c44e (patch) | |
| tree | befac10b20e0c07e7e3fa32e77fc1429e8708e53 /cli/app/sql/models/graph.py | |
| parent | 288694ae9a61c59dba91e2357fa7785d95a51341 (diff) | |
setting up the database...
Diffstat (limited to 'cli/app/sql/models/graph.py')
| -rw-r--r-- | cli/app/sql/models/graph.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/cli/app/sql/models/graph.py b/cli/app/sql/models/graph.py index ef5a817..1f553e9 100644 --- a/cli/app/sql/models/graph.py +++ b/cli/app/sql/models/graph.py @@ -1,9 +1,11 @@ -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.page import Page from app.settings import app_cfg @@ -11,16 +13,16 @@ from os.path import join class Graph(Base): """Table for storing references to graphs""" - __tablename__ = 'graphs' + __tablename__ = 'graph' id = Column(Integer, primary_key=True) path = Column(String(64, convert_unicode=True), nullable=False) title = Column(String(64, convert_unicode=True), nullable=False) 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()) - # pages = relationship("Page", secondary="pages", lazy='dynamic') + # pages = relationship('Page', lazy='dynamic') def toJSON(self): return { @@ -33,6 +35,11 @@ class Graph(Base): 'updated_at': self.updated_at, } + def toFullJSON(self): + data = self.toJSON() + data['pages'] = [ page.toJSON() for page in self.pages ] + return data + class GraphForm(ModelForm): class Meta: model = Graph |
