Files
cao_sunyata/cao_blogr/models/blog_record.py
2022-05-01 09:51:03 +02:00

48 lines
1.6 KiB
Python

import datetime #<- will be used to set default dates on models
from cao_blogr.models.meta import Base #<- we need to import our sqlalchemy metadata from which model classes will inherit
from sqlalchemy import (
Column,
Integer,
Unicode, #<- will provide Unicode field
UnicodeText, #<- will provide Unicode text field
DateTime, #<- time abstraction field
Index,
)
from webhelpers2.text import urlify #<- will generate slugs
from webhelpers2.date import distance_of_time_in_words #<- human friendly dates
class BlogRecord(Base):
__tablename__ = 'entries'
id = Column(Integer, primary_key=True)
title = Column(Unicode(255), unique=True, nullable=False)
body = Column(UnicodeText, default='')
body_html = Column(UnicodeText, default='')
tag = Column(Unicode(25), index=True)
topic = Column(Unicode(25), index=True)
created = Column(DateTime, default=datetime.datetime.utcnow)
edited = Column(DateTime, default=datetime.datetime.utcnow)
@property
def slug(self):
return urlify(self.title)
@property
def created_in_words(self):
return distance_of_time_in_words(self.created, datetime.datetime.utcnow())
class Topics(Base):
__tablename__ = 'topics'
topic = Column(Unicode(25), primary_key=True)
topic_name = Column(Unicode(25), nullable=False)
class Tags(Base):
__tablename__ = 'tags'
id = Column(Integer, primary_key=True)
topic = Column(Unicode(25))
tag = Column(Unicode(25))
tag_name = Column(Unicode(25), nullable=False)
__table_args__ = (Index('topic_index', "topic", "tag"), )