code: def remove_instance(self):
          
          with fields.FieldLock(self.related_field):
              related_pks = self()
              for pk in related_pks:
  
                  # get the real related field
                  related_instance = self.related_field._model(pk)
                  related_field = getattr(related_instance, self.related_field.name)
  
                  # check if we have a dedicated remove method
                  remover = getattr(related_field, '_related_remover', None)
  
                  # then remove the instance from the related field
                  if remover is not None:
                      # if we have a remover method, it wants the instance as argument
                      # (the related field may be a set/list/sorted_set)
                      getattr(related_field, remover)(self.instance._pk)
                  else:
                      # no remover method, simple delete the field
                      related_field.delete()
docs: Remove the instance from the related fields (delete the field if it's
          a simple one, or remove the instance from the field if it's a set/list/
          sorted_set)