Created
January 12, 2017 03:30
-
-
Save mazz/53581e919c182a61d28883bc235e75bb to your computer and use it in GitHub Desktop.
websauna admin does not detect audiostream table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Place your SQLAlchemy models in this file.""" | |
import datetime | |
from uuid import uuid4 | |
from sqlalchemy import Column, Unicode, String, Integer, ForeignKey, UnicodeText | |
from sqlalchemy.dialects.postgresql import UUID | |
from sqlalchemy.orm import relationship | |
from websauna.system.model.meta import Base | |
from websauna.system.model.columns import UTCDateTime | |
from websauna.utils.time import now | |
class Media(Base): | |
#: The table in the database | |
__tablename__ = "media" | |
#: Database primary key for the row (running counter) | |
id = Column(Integer, autoincrement=True, primary_key=True) | |
#: Publicly exposed non-guessable | |
uuid = Column(UUID(as_uuid=True), default=uuid4) | |
#: url | |
url = Column(Unicode(384), default=None) | |
#: title of content | |
title = Column(Unicode(384), default=None) | |
#: duration of content | |
duration = Column(String(8), default=None) | |
#: description of content | |
description = Column(UnicodeText, default=None) | |
#: When this content was published | |
published_at = Column(UTCDateTime, default=None) | |
#: Relationship mapping between media and audiostream. | |
#: Each audiostream can have only media. | |
#: Deleting media deletes its audiostreams. | |
audiostreams = relationship("AudioStream", | |
back_populates="media", | |
lazy="dynamic", | |
cascade="all, delete-orphan", | |
single_parent=True) | |
def is_recent(self): | |
return self.published_at >= now() - datetime.timedelta(days=1) | |
def __repr__(self): | |
return "#{}: {}".format(self.id, self.url) | |
def __str__(self): | |
"""Python default and admin UI string presentation.""" | |
return self.url | |
class AudioStream(Base): | |
#: The table in the database | |
__tablename__ = "audiostream" | |
#: Database primary key for the row (running counter) | |
id = Column(Integer, autoincrement=True, primary_key=True) | |
#: Publicly exposed non-guessable id | |
uuid = Column(UUID(as_uuid=True), default=uuid4) | |
#: What the user sees for this audiostream | |
filepath = Column(Unicode(512), default=None) | |
bitrate = Column(String(4), default=None) | |
extension = Column(String(4), default=None) | |
#: download url | |
# url = Column(Unicode(768), default=None) | |
#: Which question this choice is part of | |
media_id = Column(Integer, ForeignKey('media.id')) | |
media = relationship("Media", back_populates="audiostreams") | |
def __repr__(self): | |
"""Shell and debugger presentation.""" | |
return "#{}@{}".format(self.extension, self.bitrate) | |
def __str__(self): | |
"""Python default and admin UI string presentation.""" | |
return "#{}@{}".format(self.extension, self.bitrate) | |
Author
mazz
commented
Jan 12, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment