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
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)
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)
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)
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