In the default Pyramid code structure, there is only one models. py file. in the actual project, if you need to classify models and put it under different files, what should we do through the following file structure. change py to a package.
The code is as follows:
Myapp
_ Init _. py
Scripts
_ Init _. py
Initialize_db.py
Models
_ Init _. py
Meta. py
Foo. py
Moo. py
The above meta. py defines a other model file sharing Base and DBSession in the code.
The code is as follows:
Base = declarative_base ()
DBSession = scoped_session (sessionmaker (extension = ZopeTransactionExtension ))
Foo. py and moo. py are specific model definitions.
Foo. py and moo. py use the base defined in meta. py
To ensure that the defined model can be enabled in the program, introduce them in models/_ init _. py:
The code is as follows:
From. meta import DBSession
From. foo import Foo
From. moo import Moo