X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/e080215f07b8153ef01d6c840a4ba3a4bfc2d770..453a7ca3b9d5e7093f843b883db58f9beb1b3aa8:/floof/model/__init__.py diff --git a/floof/model/__init__.py b/floof/model/__init__.py index af26ba2..d4745a7 100644 --- a/floof/model/__init__.py +++ b/floof/model/__init__.py @@ -1,36 +1,38 @@ """The application's model objects""" -import sqlalchemy as sa -from sqlalchemy import orm - +import elixir from floof.model import meta +Session = elixir.session = meta.Session +# Uncomment if using reflected tables +# elixir.options_defaults.update({'autoload': True}) +elixir.options_defaults.update({'shortnames':True}) +metadata = elixir.metadata + +# this will be called in config/environment.py +# if not using reflected tables def init_model(engine): """Call me before using any of the tables or classes in the model""" - ## Reflected tables must be defined and mapped here - #global reflected_table - #reflected_table = sa.Table("Reflected", meta.metadata, autoload=True, - # autoload_with=engine) - #orm.mapper(Reflected, reflected_table) - # meta.Session.configure(bind=engine) - meta.engine = engine - - -## Non-reflected tables may be defined and mapped at module level -#foo_table = sa.Table("Foo", meta.metadata, -# sa.Column("id", sa.types.Integer, primary_key=True), -# sa.Column("bar", sa.types.String(255), nullable=False), -# ) -# -#class Foo(object): -# pass -# -#orm.mapper(Foo, foo_table) - - -## Classes for reflected tables may be defined here, but the table and -## mapping itself must be done in the init_model function -#reflected_table = None -# -#class Reflected(object): -# pass + metadata.bind = engine + +# Delay the setup if using reflected tables +if elixir.options_defaults.get('autoload', False) \ + and not metadata.is_bound(): + elixir.delay_setup = True + +# # import other entities here, e.g. +# from floof.model.blog import BlogEntry, BlogComment +from floof.model.art import * +from floof.model.ratings import * +from floof.model.comments import * +from floof.model.search import * +from floof.model.tags import * +from floof.model.users import * + + +# Finally, call elixir to set up the tables. +# but not if using reflected tables +if not elixir.options_defaults.get('autoload', False): + elixir.setup_all() + +