Changes between Version 53 and Version 54 of DeveloperGuidelinesNewModule


Ignore:
Timestamp:
11/29/13 22:06:48 (11 years ago)
Author:
Pat Tressel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelinesNewModule

    v53 v54  
    2525Follow with underscore and the name of the resource your table represents: <MODULE NAME>_<RESOURCE>. Resource names should be unique.
    2626
    27 E.g. if building a Vehicle Management System, create s3db.vms_vehicle:
     27E.g. if building a Vehicle Management System with module name vms, with individual vehicles and vehicle types:
    2828{{{
    29 module = "vms"
    30 resource = "vehicle"
     29__all__ = ["S3VehicleModel",
     30           "vms_vehicle",
     31           "vms_vehicle_type",
     32          ]
    3133
    32 tablename = "%s_%s" % (module, resource)
    33 table = s3db.define_table(tablename,
    34                 Field("name"),
    35                 *s3_meta_fields())
    36 table.uuid.requires = IS_NOT_IN_DB(db, "%s.uuid" % table)
    37 table.name.requires = IS_NOT_EMPTY()
    38 table.name.comment = SPAN("*", _class="req")
     34class S3VehicleModel(S3Model):
     35    """
     36        Vehicle Management
     37    """
     38
     39    names = ["vms_vehicle",
     40             "vms_vehicle_type",
     41            ]
     42
     43    def model(self):
     44
     45        T = current.T
     46        db = current.db
     47
     48        tablename = "vms_vehicle"
     49        represent = S3Represent(lookup=tablename)
     50        table = s3db.define_table(tablename,
     51                                  Field("name",
     52                                        requires = IS_NOT_EMPTY()
     53                                       ),
     54                                  Field("type",
     55                                        requires=IS_ONE_OF(db,
     56                                                           "vms_vehicle_type.id",
     57                                                           represent),
     58                                       )
     59                                  *s3_meta_fields())
    3960}}}
    4061