OMType

Author:Neil Wallace (neil@openmolar.com)
Release:2.0.906~hg207
Date:April 18, 2013

This class is used to create the custom datatypes stored in the postgres database.

Let’s take a trivial example.. how to store an individual’s sex.

It is common to do have a field defined something like this:

sex char(1) NOT NULL;
CONSTRAINT chk_sex CHECK (sex = 'M' or sex = 'F')

however, another way is to create a postgres data type:

CREATE TYPE sex_type AS ENUM ('M','F')

and use it thus:

sex sex_type NOT NULL

The OMType class does this for us, but is also a useful python object in it’s own right, storing default values, translations etc.

“Sex” is a trivial example, it quickly becomes more complex when I store an enumeration of allowed crown types, or patient statuses etc.

methods and attributes

class lib_openmolar.common.datatypes.om_types.OMType(name)[source]

Bases: object

custom postgres data type creator

__init__(name)[source]
allow(val, readable)[source]
allowed_values = None
creation_queries[source]

a list of queries to register this type in the database

default[source]

the value to use as a default returns None by default

name = None
readable_dict = None
removal_queries[source]

a list of queries to remove this type from the database

selections[source]

values as required for combobox selection

set_default(default)[source]
translate(val)[source]

returns a translated version of the key

Table Of Contents

Previous topic

NullDateEdit

Next topic

OMTypes