Changes between Version 2 and Version 3 of S3/CustomTables


Ignore:
Timestamp:
09/13/21 15:52:31 (3 years ago)
Author:
Fran Boon
Comment:

Update to new design

Legend:

Unmodified
Added
Removed
Modified
  • S3/CustomTables

    v2 v3  
    11= Custom Tables =
    22
    3 Templates can define their own custom nodels without needing to touch the core code. tablename should be "custom_%s" % resourcename
     3Templates can define their own custom models without needing to touch the core code.
    44
    5 Add a dict (or !OrderedDict if want to manage dependency order), like:
     51. 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
     72. Add this to {{{mytemplate/__init__.py}}}, e.g. for a module called 'custom':
    68{{{
    7 settings.models = {tablename: function}
     9__all__ = ("custom",
     10           )
     11
     12import templates.mytemplate.custom
    813}}}
    914
    10 The called function would look something like:
     153. Add to {{{mytemplate/config.py}}}:
    1116{{{
    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
     17settings.base.custom_models = {"custom": "mytemplate",
     18                               }
     19settings.modules["custom"] = {"name_nice": T("My Custom Module"), "module_type": 10}
    2120}}}
    2221
    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:
     224. If wanting to have a REST controller for them, then see [wiki:S3/S3REST/s3_rest_controller#Re-RoutingControllers]
     23i.e. add an entry to {{{mytemplate/config.py}}}:
    2524{{{
    2625settings.base.rest_controllers = {("custom", resourcename): ("custom", resourcename)}