Skip to content

Instantly share code, notes, and snippets.

@circuitqed
Last active August 29, 2015 13:57
Show Gist options
  • Save circuitqed/9877857 to your computer and use it in GitHub Desktop.
Save circuitqed/9877857 to your computer and use it in GitHub Desktop.
class Author(db.Model):
id = db.Column(db.Integer, primary_key=True)
forenames = db.Column(db.String(120), index=True)
lastname = db.Column(db.String(120), index=True)
#intermediate table used for ordering authors within articles
class ArticleAuthor(db.Model):
__tablename__ = 'articlesauthors'
article_id = db.Column(db.Integer, db.ForeignKey('article.id'), primary_key=True)
author_id = db.Column(db.Integer, db.ForeignKey('author.id'), primary_key=True)
position = db.Column(db.Integer)
author = db.relationship('Author')
def __init__(self, author):
self.author = author
class Article(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(120))
#These set up the ordered list of authors
_authors = db.relationship('ArticleAuthor',
collection_class=ordering_list('position'),
backref=db.backref('articles'))
authors = association_proxy('_authors', 'author')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment