Beispiel #1
0
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)
Beispiel #3
0
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)
Beispiel #4
0
class GroupSchema(ma.ModelSchema):
    items = ma.Nested('InventorySchema', exclude=["group"], many=True)

    class Meta(BaseSchema.Meta):
        model = Group
Beispiel #5
0
class JobSchema(ma.ModelSchema):
    location = ma.Nested('LocationSchema', allow_none=True)
    events = ma.Nested('EventSchema', many=True)

    class Meta(BaseSchema.Meta):
        model = Job