From 0cf304696d50cc8bba9e0e21349d4571573c5790 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 27 May 2021 19:22:47 -0700 Subject: [PATCH] More revisions --- scribeengine/models.py | 55 +++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/scribeengine/models.py b/scribeengine/models.py index be4c87f..d3106e4 100644 --- a/scribeengine/models.py +++ b/scribeengine/models.py @@ -105,27 +105,9 @@ class Node(Model): return node_dict -class Revision(Model): - """ - A version of a node - """ - __tablename__ = 'revisions' - - id = Column(Integer, primary_key=True) - version = Column(String(255), nullable=False) - title = Column(String(255), nullable=False) - body = Column(Text) - format = Column(Text, nullable=False) - slug = Column(String(255), nullable=False) - created = Column(DateTime, nullable=False, index=True, default=datetime.utcnow) - node_id = Column(Integer, ForeignKey('nodes.id'), nullable=False) - - node = relationship('Node', backref='revisions') - - class Field(Model): """ - A field is a model for extra field types on nodes + A field is a model for field types on nodes """ __tablename__ = 'fields' @@ -138,6 +120,41 @@ class Field(Model): modified = Column(DateTime, nullable=False, default=datetime.utcnow) +class FieldRevision(Model): + """ + A revision of a field on a node + """ + __tablename__ = 'field_revisions' + + id = Column(Integer, primary_key=True) + version = Column(Integer, nullable=False) + title = Column(String(255), nullable=False) + body = Column(Text) + format = Column(Text, nullable=False) + slug = Column(String(255), nullable=False) + created = Column(DateTime, nullable=False, index=True, default=datetime.utcnow) + node_id = Column(Integer, ForeignKey('nodes.id'), nullable=False) + + +class NodeField(Model): + """ + A node field is a field on a particular node + """ + __tablename__ = 'node_fields' + + id = Column(Integer, primary_key=True) + field_id = Column(Integer, ForeignKey('fields.id')) + node_id = Column(Integer, ForeignKey('nodes.id')) + revision_id = Column(Integer, ForeignKey('field_revisions.id'), nullable=False, index=True) + title = Column(String(255), nullable=False) + description = Column(Text) + created = Column(DateTime, nullable=False, default=datetime.utcnow) + modified = Column(DateTime, nullable=False, default=datetime.utcnow) + + current_revision = relationship('FieldRevision', backref='node_field') + field = relationship('Field', backref='node_field') + + class File(Model): """ A file in the media library.