Skip to content
Snippets Groups Projects
models_annotation.py 2.9 KiB
Newer Older
# coding: utf-8
"""
class StationmetaAnnotation (Base)
==================================
"""
from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, text, String, \
                       Text, Boolean, CheckConstraint
#from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base
from toardb.auth_user.models import AuthUser
from .models_core import StationmetaCore 

Base = declarative_base()
metadata = Base.metadata

class StationmetaAnnotation(Base):
    """ Table "public.stationmeta_annotations"
         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 | 
     station_id     | integer                  |           | not null | 
    Indexes:
     "stationmeta_annotations_pkey" PRIMARY KEY, btree (id)
     "stationmeta_annotations_contributor_id_a5009820" btree (contributor_id)
     "stationmeta_annotations_station_id_9d3fe3d0" btree (station_id)
    Check constraints:
     "stationmeta_annotations_kind_check" CHECK (kind >= 0)
    Foreign-key constraints:
     "stationmeta_annotati_station_id_9d3fe3d0_fk_stationme" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
     "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)
    station_id = Column(ForeignKey(StationmetaCore.id, deferrable=True, initially='DEFERRED'), nullable=False, index=True)
# how to reactivate the following two lines?!
#   contributor = relationship('AuthUser')
#   station = relationship('StationmetaCore')