Changeset 5616
- Timestamp:
- 10/25/08 12:26:35 (3 months ago)
- Files:
-
- docs/2.0/docs/main/SQLAlchemy.rst (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
docs/2.0/docs/main/SQLAlchemy.rst
r5170 r5616 22 22 23 23 * `__init__.py`: This is where the database access is setup. Your tables should be imported into this module, and you're highly encouaged to define them in a separate module - `entities`, for example. 24 * ` identity.py`: This file will be created if you enabled identity in the quickstart. It defines the three tables TG2 identityrelies on: `User` (for the registered members in your website), `Group` (for the teams a member may belong to, and to which you can assign permissions) and `Permission` (a permission granted to one or more groups); it also defines two intermediary tables: One for the many-to-many relationship between the groups and the permissions, and another one for the many-to-many relationship between the users and the groups.24 * `auth.py`: This file will be created if you enabled authentication and authorization in the quickstart. It defines the three tables :mod:`tgext.authorization.quickstart` relies on: `User` (for the registered members in your website), `Group` (for the teams a member may belong to, and to which you can assign permissions) and `Permission` (a permission granted to one or more groups); it also defines two intermediary tables: One for the many-to-many relationship between the groups and the permissions, and another one for the many-to-many relationship between the users and the groups. 25 25 26 26 Auto-reflection of tables has to happen after all the configuration is read, and the app is setup, so we provide simple init_model method (defined in `model/__init__.py`) that is not called until after everything is setup for you. … … 35 35 * The declarative method, which relies on a built-in plugin for SQLAlchemy called `Declarative <http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative>`_. This is the most intuitive method for table definition. 36 36 37 The tables defined by the quickstart in `model/ identity.py` are based on the declarative method, so you may want to check it out to see how columns are defined for these tables, as well as to see real examples of many-to-one, one-to-many and many-to-many relationships. For more information, you may read `the ORM tutorial <http://www.sqlalchemy.org/docs/05/ormtutorial.html>`_ and the documentation for `the Declarative extension <http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative>`_.37 The tables defined by the quickstart in `model/auth.py` are based on the declarative method, so you may want to check it out to see how columns are defined for these tables, as well as to see real examples of many-to-one, one-to-many and many-to-many relationships. For more information, you may read `the ORM tutorial <http://www.sqlalchemy.org/docs/05/ormtutorial.html>`_ and the documentation for `the Declarative extension <http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative>`_. 38 38 39 39 Once you have defined your tables in a separate module in the `model` package, they should be imported from `model/__init__.py`. So the end of this file would look like this: … … 42 42 43 43 # Import your model modules here. 44 from identityimport User, Group, Permission44 from auth import User, Group, Permission 45 45 # Say you defined these three classes in the 'movies' 46 46 # module of your 'model' package. … … 127 127 128 128 129 Using non-default names for identity-related tables and mapped classes130 ------------------------------------------------ ------------------------129 Using non-default names for auth-related classes 130 ------------------------------------------------ 131 131 132 If you don't want to use the default names for your identity-related tables and mapped classes, it's easy to replace them. 133 134 Once you have renamed the class names, go to `{your-app}/config/app_cfg.py` and edit these lines accordingly:: 135 136 # To replace the 'User' class by 'Member': 137 base_config.sa_auth.user_class = model.Member 138 # To use a different table name for the registered users: 139 base_config.sa_auth.users_table = 'member' 140 # To replace the 'Group' class by 'Team': 141 base_config.sa_auth.group_class = model.Team 142 # To use a different table name for the groups in your website: 143 base_config.sa_auth.groups_table = 'team' 144 # The Permission class and its table are not modified; we're happy with their names. 145 base_config.sa_auth.permission_class = model.Permission 146 base_config.sa_auth.permissions_table = 'permission' 147 132 If you don't want to use the default names for your auth-related classes, it's easy to replace them. 133 Please check the documentation for :mod:`tgext.authorization.quickstart` to 134 learn how to do it. 148 135 149 136 Quick database creation