40 lines
993 B
Python
40 lines
993 B
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))
|
|
body = db.Column(db.Text)
|
|
pub_date = db.Column(db.DateTime)
|
|
|
|
category_id = db.Column(db.Integer, db.ForeignKey('category.id'))
|
|
category = db.relationship('Category',
|
|
backref=db.backref('posts', lazy='dynamic'))
|
|
|
|
def __init__(self, title, body, category, pub_date=None):
|
|
self.title = title
|
|
self.body = body
|
|
if pub_date is None:
|
|
pub_date = datetime.utcnow()
|
|
self.pub_date = pub_date
|
|
self.category = category
|
|
|
|
def __repr__(self):
|
|
return '<Post %r>' % self.title
|
|
|
|
|
|
class Category(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(50))
|
|
|
|
def __init__(self, name):
|
|
self.name = name
|
|
|
|
def __repr__(self):
|
|
return '<Category %r>' % self.name
|