X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/68a31d533aba7490c3f1f812075e8ab6eb9265d0..525fe6090b7ff002198c4a58dc9cb90d774b8cd0:/floof/model/__init__.py?ds=sidebyside diff --git a/floof/model/__init__.py b/floof/model/__init__.py index d0f03b3..9cacd18 100644 --- a/floof/model/__init__.py +++ b/floof/model/__init__.py @@ -1,21 +1,33 @@ """The application's model objects""" -import sqlalchemy as sa -from sqlalchemy import orm - +import elixir from floof.model import meta -# Tables are defined in separate files and imported to here -from floof.model.users import * -from floof.model.art import * +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 + 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 Art +from floof.model.users import User, IdentityURL + +# 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() +