def _toggle_like(doctype, name, add, user=None):
 if (not user):
  user = frappe.session.user
 try:
  liked_by = frappe.db.get_value(doctype, name, u'_liked_by')
  if liked_by:
   liked_by = json.loads(liked_by)
  else:
   liked_by = []
  if (add == u'Yes'):
   if (user not in liked_by):
    liked_by.append(user)
    add_comment(doctype, name)
  elif (user in liked_by):
   liked_by.remove(user)
   remove_like(doctype, name)
  frappe.db.set_value(doctype, name, u'_liked_by', json.dumps(liked_by), update_modified=False)
 except Exception as e:
  if (isinstance(e.args, (tuple, list)) and e.args and (e.args[0] == 1054)):
   add_column(doctype, u'_liked_by', u'Text')
   _toggle_like(doctype, name, add, user)
  else:
   raise

def _toggle_like ( doctype , name , add , user = None ) : if ( not user ) : user = frappe . session . user try : liked_by = frappe . db . get_value ( doctype , name , u'_liked_by' ) if liked_by : liked_by = json . loads ( liked_by ) else : liked_by = [ ] if ( add == u'Yes' ) : if ( user not in liked_by ) : liked_by . append ( user ) add_comment ( doctype , name ) elif ( user in liked_by ) : liked_by . remove ( user ) remove_like ( doctype , name ) frappe . db . set_value ( doctype , name , u'_liked_by' , json . dumps ( liked_by ) , update_modified = False ) except Exception as e : if ( isinstance ( e . args , ( tuple , list ) ) and e . args and ( e . args [ 0 ] == 1054 ) ) : add_column ( doctype , u'_liked_by' , u'Text' ) _toggle_like ( doctype , name , add , user ) else : raise
same as toggle_like but hides param user from api .