class Post(db.Model):
    id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(80))
url = db.Column(db.String(120))
body = db.Column(db.Text)
create_date = db.Column(db.DateTime)
pub_date = db.Column(db.DateTime)
pub_status = db.Column(db.Text(80))
author_id = db.Column(db.Integer, db.ForeignKey('user.id'))
author = db.relationship('User', backref=db.backref('posts', lazy='dynamic'))
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.category = category
self.pub_date = pub_date

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))
description = db.Column(db.String(250))

def __init__(self, name):
    self.name = name

def __repr__(self):
    return self.name
A Complete Many-to-One Example Using Flask, WTForm, SQLAlchemy, and Jinja2