Appearance
Relationships
Setting a relationship
Use ResourceTuple(uuid, "resource-type") to assign a relationship. The resource type is the JSON:API plural resource name (kebab-case):
python
import asyncio
from cacholong_sdk import connection, DnsZone, ResourceTuple
async def main():
async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
ctrl = DnsZone(api)
zone = ctrl.create()
zone["domain"] = "example.com"
zone["account"] = ResourceTuple("ACCOUNT-UUID", "accounts")
await ctrl.store(zone)
asyncio.run(main())The same syntax works when updating a relationship on an existing resource.
Reading a relationship
Relationships are not automatically fetched with a resource. Call .fetch() on the relationship object before accessing its attributes:
python
import asyncio
from cacholong_sdk import connection, DnsZone
async def main():
async with connection("https://api.cacholong.eu/api/v1/", "YOUR-API-KEY") as api:
ctrl = DnsZone(api)
zone = await ctrl.fetch("ZONE-UUID")
account_rel = zone["account"]
account = await account_rel.fetch()
print(account["name"])
asyncio.run(main())