Return the value to insert in a relationship cell

def _get_relationship_cell_val(self, obj, column):
        """
        Return the value to insert in a relationship cell
        """
        val = ""
        key = column['key']
        related_key = column.get('related_key', None)

        related_obj = getattr(obj, key, None)

        if related_obj is None:
            return ""

        if column['__col__'].uselist:  # OneToMany
            # We know how to retrieve a value from the related objects
            if related_key is not None:
                # Only the related object of the given index
                if column.get('index') is not None:
                    if len(related_obj) > column['index']:
                        rel_obj = related_obj[column['index']]
                        val = self._get_formatted_val(
                            rel_obj,
                            related_key,
                            column,
                        )
                # We join all the related objects val
                else:
                    _vals = []
                    for rel_obj in related_obj:
                        _vals.append(
                            self._get_formatted_val(
                                rel_obj,
                                related_key,
                                column,
                            )
                        )
                    val = '\n'.join(_vals)
        else:  # Many to One
            if related_key is not None:
                val = self._get_formatted_val(related_obj, related_key, column)

        return val