This is a real example which illustrates a one-to-many relationship between one Location and many Devices.
From Device.py
... from Products.ZenRelations.RelSchema import * ... class Device(ManagedEntity, Commandable): ... event_key= portal_type = meta_type = 'Device' default_catalog= "deviceSearch" #device ZCatalog relationshipManagerPathRestriction = '/Devices' ... _relations = ManagedEntity._relations + ( ("location", ToOne(ToMany, "Location", "devices")), ) ...
From Location.py
... from Products.ZenRelations.RelSchema import *... class Location(DeviceOrganizer): ... # Organizer configuration dmdRootName = "Locations" portal_type = meta_type = event_key = 'Location' _relations = DeviceOrganizer._relations + ( ("devices" , ToMany(ToOne,"Device","location")), ) ...
According to this relationship there can be only one Location assigned to a Device but more than one Device assigned to a Location. This relationship is created by:
Importing ToOne and ToMany from Products.ZenRelations.RelSchema. | |
Appending a two-item tuple to the _relations attribute | |
The first item in the tuple is a "string" object which is the local name | |
The second item in the tuple is a RelSchema constructors takes three parameters:
|