From ab51e83e9c99f06168685d72cd286785b1fa0a8d Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 29 Sep 2019 11:05:13 +0100 Subject: [PATCH] New table for paintings --- depicts/model.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/depicts/model.py b/depicts/model.py index 6912cfa..9e87508 100644 --- a/depicts/model.py +++ b/depicts/model.py @@ -5,6 +5,7 @@ from sqlalchemy.types import Integer, String, DateTime from sqlalchemy.orm import column_property, relationship from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.sql.expression import cast +from sqlalchemy.dialects import postgresql from urllib.parse import quote Base = declarative_base() @@ -35,16 +36,27 @@ class DepictsItemAltLabel(Base): def __init__(self, alt_label): self.alt_label = alt_label +class PaintingItem(Base): + __tablename__ = 'painting' + item_id = Column(Integer, primary_key=True, autoincrement=False) + label = Column(String) + entity = Column(postgresql.JSON) + qid = column_property('Q' + cast(item_id, String)) + class Edit(Base): __tablename__ = 'edit' username = Column(String, primary_key=True) - painting_id = Column(Integer, primary_key=True) - depicts_id = Column(Integer, primary_key=True) + painting_id = Column(Integer, ForeignKey('painting.item_id'), primary_key=True) + depicts_id = Column(Integer, ForeignKey('depicts.item_id'), primary_key=True) timestamp = Column(DateTime, default=now_utc()) + lastrevid = Column(Integer, nullable=True) painting_qid = column_property('Q' + cast(painting_id, String)) depicts_qid = column_property('Q' + cast(depicts_id, String)) + painting = relationship('PaintingItem') + depicts = relationship('DepictsItem') + @property def user_page_url(self): start = 'https://www.wikidata.org/wiki/User:'