La version 5 de Planète Casio. Regroupe le forum, les programmes, les tutoriel, les sprites et tous les autres outils développés par nos soins.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

58 lines
1.4 KiB

from app import db
from datetime import datetime
class Post(db.Model):
"""Contents created and published by Users."""
__tablename__ = 'post'
# Unique Post ID for the whole site
id = db.Column(db.Integer, primary_key=True)
# Post type (polymorphic discriminator)
type = db.Column(db.String(20))
# Creation and edition date
date_created = db.Column(db.DateTime)
date_modified = db.Column(db.DateTime)
# Post author
author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
author = db.relationship('User', backref="posts", foreign_keys=author_id)
# TODO: Post attachments?
__mapper_args__ = {
'polymorphic_identity': __tablename__,
'polymorphic_on': type
}
def __init__(self, author):
"""
Create a new Post.
Arguments:
author -- post author (User)
"""
self.author = author
self.date_created = datetime.now()
self.date_modified = self.date_created
def touch(self):
"""Touch a Post when it is edited."""
self.date_modified = datetime.now()
def change_ownership(self, new_author):
"""
Change ownership of a Post. This is a privileged operation!
Arguments:
new_author -- new post author (User)
"""
self.author = new_author
def __repr__(self):
return f'<Post: #{self.id}>'