def add_relation(self,<EOL>target_id=None,<EOL>relation_types=None,<EOL>fact_dt_namespace_name=None,<EOL>fact_dt_namespace_uri=DINGOS_NAMESPACE_URI,<EOL>fact_dt_kind=FactDataType.UNKNOWN_KIND,<EOL>fact_dt_name='<STR_LIT>',<EOL>metadata_dict=None,<EOL>markings=None<EOL>):
if not markings:<EOL><INDENT>markings = []<EOL><DEDENT>if relation_types == None:<EOL><INDENT>relation_types = []<EOL><DEDENT>relation_type_ft, created = get_or_create_fact_term(iobject_family_name=self.iobject_family.name,<EOL>fact_term_name=DINGOS_RELATION_TYPE_FACTTERM_NAME,<EOL>iobject_type_name=self.iobject_type.name,<EOL>iobject_type_namespace_uri=self.iobject_type.namespace.uri,<EOL>fact_dt_name=fact_dt_name,<EOL>fact_dt_namespace_name=fact_dt_namespace_name,<EOL>fact_dt_kind=fact_dt_kind,<EOL>fact_dt_namespace_uri=fact_dt_namespace_uri)<EOL>relation_type_fact, created = get_or_create_fact(fact_term=relation_type_ft,<EOL>fact_dt_name=fact_dt_name,<EOL>fact_dt_namespace_uri=fact_dt_namespace_uri,<EOL>values=relation_types,<EOL>value_iobject_id=None,<EOL>value_iobject_ts=None,<EOL>)<EOL>rel_target_id = target_id<EOL>rel_source_id = self.identifier<EOL>relation, created = self._DCM['<STR_LIT>'].objects.get_or_create(<EOL>source_id=rel_source_id,<EOL>target_id=rel_target_id,<EOL>relation_type=relation_type_fact)<EOL>for marking in markings:<EOL><INDENT>Marking2X.objects.create(marked=relation,<EOL>marking=marking)<EOL><DEDENT>if metadata_dict:<EOL><INDENT>if relation.metadata_id:<EOL><INDENT>rel_identifier_uid = relation.metadata_id.uid<EOL>rel_identifier_namespace_uri = relation.metadata_id.namespace.uri<EOL><DEDENT>else:<EOL><INDENT>rel_identifier_uid = None<EOL>rel_identifier_namespace_uri = DINGOS_ID_NAMESPACE_URI<EOL><DEDENT>metadata_iobject, created = get_or_create_iobject(identifier_uid=rel_identifier_uid,<EOL>identifier_namespace_uri=rel_identifier_namespace_uri,<EOL>iobject_type_name=DINGOS_RELATION_METADATA_OBJECT_TYPE_NAME,<EOL>iobject_type_namespace_uri=DINGOS_NAMESPACE_URI,<EOL>iobject_type_revision_name=DINGOS_REVISION_NAME,<EOL>iobject_family_name=DINGOS_IOBJECT_FAMILY_NAME,<EOL>iobject_family_revision_name=DINGOS_REVISION_NAME,<EOL>timestamp=None,<EOL>overwrite=False)<EOL>metadata_iobject.from_dict(metadata_dict)<EOL><DEDENT>return relation<EOL>
Add a relationship between this object and another object.