typeset-blog/app/models.py

55 lines
1.4 KiB
Python

# -*- encoding: utf-8 -*-
"""
Python Aplication Template
Licence: GPLv3
"""
from app import db
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(80))
content = db.Column(db.Text)
# pub_date = db.Column(db.DateTime)
def __init__(self, title,content, pub_date=None):
self.title = title
self.content = content
# if pub_date is None:
# pub_date = datetime.utcnow()
# self.pub_date = pub_date
# paragraphs = text.split('\n\n')
# self.paragraphs = paragraphs
def __repr__(self):
return '<Post %r>' % self.title
class Paragraph(db.Model):
id = db.Column(db.Integer, primary_key=True)
body = db.Column(db.Text)
post_id = db.Column(db.Integer, db.ForeignKey('post.id'))
def __init__(self, body,post_id):
self.body = body
self.post_id = post_id
def __repr__(self):
return '<Post %r>' % self.title
class Comment(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(50))
message = db.Column(db.String(140))
paragraph_id = db.Column(db.Integer, db.ForeignKey('paragraph.id'))
db.relationship('Paragraph',backref=db.backref('comments', lazy='dynamic'))
def __init__(self, name,message):
self.name = name
self.message = message
def __repr__(self):
return '<Comment %r>' % self.name
db.create_all()