Skip to content

Instantly share code, notes, and snippets.

@agronholm
Forked from circuitqed/gist:9877857
Last active August 29, 2015 13:57
Show Gist options
  • Save agronholm/9881846 to your computer and use it in GitHub Desktop.
Save agronholm/9881846 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)
associations = db.relationship('ArticleAuthor', backref='author')
articles = association_proxy('associations', 'article')
#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)
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
associations = db.relationship('ArticleAuthor',
collection_class=ordering_list('position'),
backref='article')
authors = association_proxy('associations', 'author')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment