コード例 #1
0
class ArticleResource(api.Resource):

    api_type = "article"
    model = Article
    attributes = [
        "title",
    ]
    relationships = {
        "tags": api.Relationship("articletag", collection=True),
        "author": api.Relationship("author"),
    }

    @property
    def id(self):
        return self.obj.pk
コード例 #2
0
ファイル: resources.py プロジェクト: pombredanne/kel-api
class SiteResource(api.Resource):

    api_type = "sites"
    model = Site
    attributes = [
        "name",
        "created",
    ]
    relationships = {
        "instances": api.Relationship("instances", collection=True),
        "services": api.Relationship("services", collection=True),
    }

    @property
    def id(self):
        return self.obj.name

    def create(self, **kwargs):
        resource_group = kwargs.pop("resource_group")
        self.obj.resource_group = resource_group
        return super(SiteResource, self).create(**kwargs)
コード例 #3
0
ファイル: resources.py プロジェクト: pombredanne/kel-api
class InstanceResource(api.Resource):

    api_type = "instances"
    model = Instance
    attributes = [
        "label",
        "created",
    ]
    relationships = {
        "site": api.Relationship("site"),
    }

    @property
    def id(self):
        return self.obj.label

    def create(self, **kwargs):
        site = kwargs.pop("site")
        self.obj.site = site
        return super(InstanceResource, self).create(**kwargs)
コード例 #4
0
ファイル: resources.py プロジェクト: pombredanne/kel-api
class ServiceResource(api.Resource):

    api_type = "services"
    model = Service
    attributes = [
        "name",
        "created",
    ]
    relationships = {
        "site": api.Relationship("sites"),
    }

    @property
    def id(self):
        return self.obj.name

    def create(self, **kwargs):
        site = kwargs.pop("site")
        self.obj.site = site
        return super(ServiceResource, self).create(**kwargs)
コード例 #5
0
ファイル: resources.py プロジェクト: pombredanne/kel-api
class ResourceGroupResource(api.Resource):

    api_type = "resource-groups"
    model = ResourceGroup
    attributes = [
        "name",
        "created",
    ]
    relationships = {
        "sites": api.Relationship("sites", collection=True),
    }

    @property
    def id(self):
        return self.obj.name

    def create(self, **kwargs):
        owner = kwargs.pop("owner")
        obj = super(ResourceGroupResource, self).create(**kwargs)
        obj.set_owner(owner)
        return obj