Last active
August 29, 2015 13:57
-
-
Save circuitqed/9877857 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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