plone.api.relation

plone.api.relation#

Module that provides functionality for relations.

Heavily inspired by collective.relationhelpers.

plone.api.relation.create(source=None, target=None, relationship=None)[source]#

Create a relation from source to target using zc.relation.

Parameters:
  • source (Content object) -- [required] Object that the relation will originate from.

  • target (Content object) -- [required] Object that the relation will point to.

  • relationship -- [required] Relationship name. If that name is the same as a field name and this field is a RelationChoice / RelationList we will update the field-value accordingly.

Example:

Create relation

plone.api.relation.delete(source=None, target=None, relationship=None)[source]#

Delete relation or relations.

Parameters:
  • source (Content object) -- Object that the relation originates from.

  • target (Content object) -- Object that the relation points to.

  • relationship -- Relationship name. If that name is the same as a field name and this field is a RelationChoice/RelationList we will delete/update the field-value accordingly.

Example:

Delete relation

plone.api.relation.get(source=None, target=None, relationship=None, unrestricted=False, as_dict=False)[source]#

Get specific relations given a source/target/relationship.

Parameters:
  • source (Content object) -- Object that the relations originate from.

  • target (Content object) -- Object that the relations point to.

  • relationship -- Relationship name.

  • unrestricted -- If true bypass permission-check on source and target.

  • as_dict -- If true, return a dictionary with the relationship name as keys.

Returns:

A list of relations

Return type:

List of RelationValue objects

Example:

Get relations