# -*- coding: utf-8 -*- # vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 ############################################################################### # ScribeEngine - Open Source Blog Software # # --------------------------------------------------------------------------- # # Copyright (c) 2010 Raoul Snyman # # --------------------------------------------------------------------------- # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the Free # # Software Foundation; version 2 of the License. # # # # This program is distributed in the hope that it will be useful, but WITHOUT # # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # # more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ The application's model objects """ from sqlalchemy.orm import mapper, relation, backref from scribeengine.model import meta from scribeengine.model.tables import categories_table, comments_table, \ files_table, media_types_table, pages_table, permissions_table, \ posts_table, roles_table, tags_table, users_table, variables_table, \ categories_posts_table, permissions_roles_table, posts_tags_table, \ roles_users_table from scribeengine.model.classes import Category, Comment, File, MediaType, \ Page, Permission, Post, Role, Tag, User, Variable def init_model(engine): """Call me before using any of the tables or classes in the model""" meta.Session.configure(bind=engine) meta.engine = engine mapper(Category, categories_table) mapper(Comment, comments_table) mapper(File, files_table) mapper(MediaType, media_types_table, properties={ u'files': relation(File, backref=u'media_type') } ) mapper(Page, pages_table) mapper(Permission, permissions_table) mapper(Post, posts_table, properties={ u'categories': relation(Category, backref=u'posts', secondary=categories_posts_table), u'comments': relation(Comment, backref=u'post', order_by=Comment.created.asc()), u'tags': relation(Tag, backref=backref(u'posts', order_by='posts.created DESC'), secondary=posts_tags_table) } ) mapper(Role, roles_table, properties={ u'permissions': relation(Permission, backref=u'roles', secondary=permissions_roles_table) } ) mapper(Tag, tags_table) mapper(User, users_table, properties={ u'comments': relation(Comment, backref=u'user'), u'files': relation(File, backref=u'user'), u'posts': relation(Post, backref=u'user'), u'roles': relation(Role, backref=u'users', secondary=roles_users_table) } ) mapper(Variable, variables_table)