Newer
Older
# coding: utf-8
"""
class StationmetaAnnotation (Base)
==================================
"""

Sabine Schröder
committed
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \

Sabine Schröder
committed
Text, Boolean, CheckConstraint, Table, Sequence, text

Sabine Schröder
committed
from sqlalchemy.orm import relationship

Sabine Schröder
committed
from toardb.auth_user.models import AuthUser

Sabine Schröder
committed
from toardb.base import Base
# many-to-many relationships
stationmeta_core_stationmeta_annotations_table = Table('stationmeta_core_stationmeta_annotations', Base.metadata,
Column('station_id', Integer, ForeignKey('stationmeta_core.id')),
Column('annotation_id', Integer, ForeignKey('stationmeta_annotations.id'))
)

Sabine Schröder
committed
STATIONMETA_ANNOTATIONS_ID_SEQ = Sequence('stationmeta_annotations_id_seq') # define sequence explicitly
class StationmetaAnnotation(Base):
""" Table "public.stationmeta_annotations"

Sabine Schröder
committed

Sabine Schröder
committed
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| Column | Type | Collation | Nullable | Default |
+================+==========================+===========+==========+========================================================+
| id | integer | | not null | nextval('stationmeta_annotations_id_seq'::regclass) |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+

Sabine Schröder
committed
| kind | integer | | not null | 0 |

Sabine Schröder
committed
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| text | text | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| date_added | timestamp with time zone | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| approved | boolean | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
| contributor_id | integer | | not null | |
+----------------+--------------------------+-----------+----------+--------------------------------------------------------+
Indexes:
"stationmeta_annotations_pkey" PRIMARY KEY, btree (id)
"stationmeta_annotations_contributor_id_a5009820" btree (contributor_id)
Check constraints:
"stationmeta_annotations_kind_check" CHECK (kind >= 0)
Foreign-key constraints:
"stationmeta_annotations_contributor_id_a5009820_fk_auth_user_id" FOREIGN KEY (contributor_id) REFERENCES auth_user(id) DEFERRABLE INITIALLY DEFERRED

Sabine Schröder
committed
"stationmeta_annotations_kind_fk_ak_vocabulary_enum_val" FOREIGN KEY (kind) REFERENCES ak_vocabulary(enum_val)
"""
__tablename__ = 'stationmeta_annotations'
__table_args__ = (
CheckConstraint('kind >= 0'),
)

Sabine Schröder
committed
id = Column(Integer, STATIONMETA_ANNOTATIONS_ID_SEQ, primary_key=True, server_default=STATIONMETA_ANNOTATIONS_ID_SEQ.next_value())

Sabine Schröder
committed
kind = Column(ForeignKey('ak_vocabulary.enum_val'), nullable=False, server_default=text("0'::integer"))
text = Column(Text, nullable=False)
date_added = Column(DateTime(True), nullable=False)
approved = Column(Boolean, nullable=False)
# do not use string declaration here (not working for pytest)
# use the explicit class name here,
# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U
contributor_id = Column(ForeignKey(AuthUser.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True)
# how to reactivate the following two lines?!
# contributor = relationship('AuthUser')

Sabine Schröder
committed

Sabine Schröder
committed
station = relationship("StationmetaCore",

Sabine Schröder
committed
secondary=stationmeta_core_stationmeta_annotations_table,
backref="annotations")