Changes between Version 2 and Version 3 of S3/CustomTables
- Timestamp:
- 09/13/21 15:52:31 (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3/CustomTables
v2 v3 1 1 = Custom Tables = 2 2 3 Templates can define their own custom nodels without needing to touch the core code. tablename should be "custom_%s" % resourcename3 Templates can define their own custom models without needing to touch the core code. 4 4 5 Add a dict (or !OrderedDict if want to manage dependency order), like: 5 1. Create a file with S3Model(s) in, just as if it was going into {{{s3db/}}} although change the s3 import path to {{{from s3 import *}}} 6 7 2. Add this to {{{mytemplate/__init__.py}}}, e.g. for a module called 'custom': 6 8 {{{ 7 settings.models = {tablename: function} 9 __all__ = ("custom", 10 ) 11 12 import templates.mytemplate.custom 8 13 }}} 9 14 10 The called function would look something like:15 3. Add to {{{mytemplate/config.py}}}: 11 16 {{{ 12 def define_custom_test(db, tablename): 13 14 from gluon import Field 15 16 table = db.define_table(tablename, 17 Field("test"), 18 ) 19 20 return table 17 settings.base.custom_models = {"custom": "mytemplate", 18 } 19 settings.modules["custom"] = {"name_nice": T("My Custom Module"), "module_type": 10} 21 20 }}} 22 21 23 If wanting to have a REST controller for them, then see [wiki:S3/S3REST/s3_rest_controller#Re-RoutingControllers]24 i.e. add "custom" to settings.modules and add an entry to the rest_controllers:22 4. If wanting to have a REST controller for them, then see [wiki:S3/S3REST/s3_rest_controller#Re-RoutingControllers] 23 i.e. add an entry to {{{mytemplate/config.py}}}: 25 24 {{{ 26 25 settings.base.rest_controllers = {("custom", resourcename): ("custom", resourcename)}