From 7ba69225297e9034b1259aef05b3038c10d43523 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Mon, 3 May 2010 13:05:42 +0200 Subject: [PATCH] Moved relations for nicer code. --- flask_website/database.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flask_website/database.py b/flask_website/database.py index 9fbcae01..007e1916 100644 --- a/flask_website/database.py +++ b/flask_website/database.py @@ -62,13 +62,14 @@ class Snippet(Model): __tablename__ = 'snippets' id = Column('snippet_id', Integer, primary_key=True) author_id = Column(Integer, ForeignKey('users.user_id')) - author = relation(User, backref=backref('snippets', lazy='dynamic')) category_id = Column(Integer, ForeignKey('categories.category_id')) - category = relation(Category, backref=backref('snippets', lazy='dynamic')) title = Column(String(200)) body = Column(String) pub_date = Column(DateTime) + author = relation(User, backref=backref('snippets', lazy='dynamic')) + category = relation(Category, backref=backref('snippets', lazy='dynamic')) + def __init__(self, author, title, body, category): self.author = author self.title = title @@ -90,13 +91,14 @@ class Comment(Model): __tablename__ = 'comments' id = Column('comment_id', Integer, primary_key=True) snippet_id = Column(Integer, ForeignKey('snippets.snippet_id')) - snippet = relation(Snippet, backref=backref('comments', lazy=True)) author_id = Column(Integer, ForeignKey('users.user_id')) - author = relation(User, backref=backref('comments', lazy='dynamic')) title = Column(String(200)) text = Column(String) pub_date = Column(DateTime) + snippet = relation(Snippet, backref=backref('comments', lazy=True)) + author = relation(User, backref=backref('comments', lazy='dynamic')) + def __init__(self, snippet, author, title, text): self.snippet = snippet self.author = author