Pyramid: How to distribute the content of the models. py file to multiple files

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.