Newer
Older
# coding: utf-8
"""
class StationmetaAnnotation (Base)
==================================
"""
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, text, String, \

Sabine Schröder
committed
Text, Boolean, CheckConstraint, Table
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'))
)
class StationmetaAnnotation(Base):
""" Table "public.stationmeta_annotations"

Sabine Schröder
committed
+----------------+--------------------------+-----------+----------+----------------------------------------------------+
| Column | Type | Collation | Nullable | Default |
+================+==========================+===========+==========+====================================================+
| id | integer | | not null | nextval('station_annotations_id_seq'::regclass) |
+----------------+--------------------------+-----------+----------+----------------------------------------------------+
| kind | integer | | not null | |
+----------------+--------------------------+-----------+----------+----------------------------------------------------+
| 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
"""
__tablename__ = 'stationmeta_annotations'
__table_args__ = (
CheckConstraint('kind >= 0'),
)
id = Column(Integer, primary_key=True, server_default=text("nextval('stationmeta_annotations_id_seq'::regclass)"))
kind = Column(Integer, nullable=False)
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
stationmeta_core = relationship("StationmetaCore",
secondary=stationmeta_core_stationmeta_annotations_table,
backref="annotations")