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.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

43 lines
1.3 KiB

  1. from datetime import datetime
  2. from app import db
  3. from app.models.users import *
  4. class Post(db.Model):
  5. __tablename__ = 'post'
  6. id = db.Column(db.Integer, primary_key=True)
  7. type = db.Column(db.String(20))
  8. __mapper_args__ = {
  9. 'polymorphic_identity': __tablename__,
  10. 'polymorphic_on': type
  11. }
  12. # Standalone properties
  13. text = db.Column(db.Text(convert_unicode=True))
  14. date_created = db.Column(db.DateTime, default=datetime.now)
  15. date_modified = db.Column(db.DateTime, default=datetime.now)
  16. # Relationships
  17. author_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
  18. def __init__(self, author, text):
  19. """ Create a Post """
  20. self.text = text
  21. if type(author) == Member:
  22. author = author.id
  23. self.author_id = author
  24. def update(self, text):
  25. """ Update a post. Check whether the request sender has the right to do
  26. this! """
  27. self.text = text
  28. self.date_modified = datetime.now()
  29. def change_ownership(self, new_author):
  30. """ Change ownership of a post. Check whether the request sender has the
  31. right to do this! """
  32. if type(new_author) == Member:
  33. new_author = new_author.id
  34. self.author_id = new_author
  35. def __repr__(self):
  36. return f'<Post: #{self.id}>'