| 296 | == Utilities == |
| 297 | |
| 298 | === Table Configuration Settings === |
| 299 | |
| 300 | {{{S3Model}}} provides a key-value store for each table which is used to store per-table configuration settings. |
| 301 | |
| 302 | The following functions can be used to manage table configuration settings: |
| 303 | |
| 304 | ||= '''Function''' =||= '''Use-Case''' =|| |
| 305 | ||{{{configure(<tablename>, <key>=<value>, <key>=<value>, ...)}}}||to add or change configuration settings for a table|| |
| 306 | ||{{{get_config(<tablename>, <key>, <default>)}}}||to retrieve a configuration setting|| |
| 307 | ||{{{clear_config(<tablename>, <key>)}}}||to remove a configuration setting for a table|| |
| 308 | |
| 309 | '''Note:''' In {{{get_config()}}}, the <default> parameter is optional (default: {{{None}}}), it will be returned if <key> is not configured for this table. |
| 310 | |
| 311 | '''Note:''' These functions are available both as instance methods in S3Models (self.* or current.s3db.*) and as class methods (S3Model.*). |
| 312 | |
| 313 | '''Important:''': {{{get_config()}}} does ''not'' load the respective model class. Settings configured inside the model class are therefore only available outside of it (e.g. with {{{s3db.get_config()}}}) if the model has been loaded before (e.g. with {{{s3db.<tablename>}}})! |
| 314 | |
| 315 | Example: |
| 316 | {{{#!python |
| 317 | # Configure list_fields for the org_organisation table |
| 318 | s3db.configure("org_organisation", |
| 319 | list_fields=["id", |
| 320 | "name", |
| 321 | "acronym", |
| 322 | "organisation_type_id", |
| 323 | "country", |
| 324 | "website"]) |
| 325 | }}} |
| 326 | |