Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2204 (closed enhancement: fixed)

Opened 8 years ago

Last modified 8 years ago

[PATCH] In the docs, add an example of using the model outside of the project

Reported by: BruceWebber Owned by: percious
Priority: normal Milestone: 2.1 docs
Component: Documentation Version: trunk
Severity: normal Keywords:
Cc:

Description

See the attached patch to the TG2 documentation. This renames the section "Using AppConfig? outside of a quickstarted project:" to "Using your model outside of a quickstarted project" and provides an example for doing that.

Attachments

using-model-outside-project.diff Download (1.9 KB) - added by BruceWebber 8 years ago.
Patch (diff) file to the documentation

Change History

Changed 8 years ago by BruceWebber

Patch (diff) file to the documentation

comment:1 Changed 8 years ago by lszyba1

Alternative example of the real code. The patch has some weird "here" statement which is not clear.... :

#tg2 session--------
import os
from paste.deploy import appconfig
import transaction
from sqlalchemy import create_engine
from myapp.model import *

conf_dict = appconfig('config:%s' % os.path.join(os.getcwd(),
'development.ini'))
engine = create_engine(conf_dict['sqlalchemy.url'])
engine.echo=True
init_model(engine)
#end of tg2 session

from myapp.model import DBSession, metadata
from myapp.model.mymodule import mytable
import transaction

#Start code below.
#DBSession.qury(mytable).....etc



#End of my code.

transaction.commit()

comment:2 Changed 8 years ago by pitrou

There seems to be a slight mistake in that example. If you want it to take the ini file from the place where the script is, you should use os.path.dirname(os.path.abspath(__file__)), not os.getcwd().

comment:3 Changed 8 years ago by mramm

  • Milestone changed from 2.0rc1 to 2.0rc2

comment:4 Changed 8 years ago by Chris Arndt

  • Owner changed from Chris Arndt to pedersen

comment:5 Changed 8 years ago by percious

  • Milestone changed from 2.1a1 to 2.1 docs

comment:6 Changed 8 years ago by percious

  • Status changed from new to assigned
  • Owner changed from pedersen to percious

comment:7 Changed 8 years ago by percious

  • Status changed from assigned to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.