class DeviceSchema(ma.ModelSchema): inventorys = ma.Nested('InventorySchema', exclude=["device"], dump_only=True, many=True) tags = ma.Nested('TagSchema', many=True) class Meta(BaseSchema.Meta): model = Device
class InventorySchema(ma.ModelSchema): device = ma.Nested('DeviceSchema', exclude=["inventorys"]) owners = ma.Nested('UserSchema', many=True) instances = ma.Nested('InstanceSchema', exclude=["inventory"], many=True) group = ma.Nested('GroupSchema', exclude=["items"], allow_none=True) class Meta(BaseSchema.Meta): model = Inventory instances_count = ma.Method("get_instances_count") def get_instances_count(self, obj): return len(obj.instances)
class DeviceSchemaSmall(ma.ModelSchema): inventorys = ma.Nested('InventorySchema', exclude=["device", "instances"], dump_only=True, many=True) tags = ma.Nested('TagSchema', many=True) class Meta(BaseSchema.Meta): model = Device all_instances_count = ma.Method("get_all_instances_count") def get_all_instances_count(self, obj): return sum(len(inventory.instances) for inventory in obj.inventorys)
class GroupSchema(ma.ModelSchema): items = ma.Nested('InventorySchema', exclude=["group"], many=True) class Meta(BaseSchema.Meta): model = Group
class JobSchema(ma.ModelSchema): location = ma.Nested('LocationSchema', allow_none=True) events = ma.Nested('EventSchema', many=True) class Meta(BaseSchema.Meta): model = Job