mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 10:51:36 -04:00
35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
from sqlalchemy import Integer, Column, String, Computed
|
|
from sqlalchemy.orm import deferred
|
|
|
|
from wrolpi.common import Base, ModelHelper, get_media_directory, tsvector
|
|
from wrolpi.dates import TZDateTime
|
|
from wrolpi.media_path import MediaPathType
|
|
|
|
|
|
class File(ModelHelper, Base):
|
|
__tablename__ = 'file'
|
|
id = Column(Integer, primary_key=True)
|
|
path = Column(MediaPathType)
|
|
|
|
mimetype = Column(String)
|
|
modification_datetime = Column(TZDateTime)
|
|
size = Column(Integer)
|
|
title = deferred(Column(String)) # used by textsearch column
|
|
|
|
textsearch = deferred(
|
|
Column(tsvector, Computed('''to_tsvector('english'::regconfig, title)''')))
|
|
|
|
def __repr__(self):
|
|
return f'<File id={self.id} path={self.path.relative_to(get_media_directory())} mime={self.mimetype}>'
|
|
|
|
def __json__(self):
|
|
path = self.path.path.relative_to(get_media_directory())
|
|
d = dict(
|
|
id=self.id,
|
|
mimetype=self.mimetype,
|
|
modification_datetime=self.modification_datetime,
|
|
path=path,
|
|
size=self.size,
|
|
key=path,
|
|
)
|
|
return d
|