def parse_m2m(commands):
 ids = []
 for command in commands:
  if isinstance(command, (tuple, list)):
   if (command[0] in (1, 4)):
    ids.append(command[1])
   elif (command[0] == 5):
    ids = []
   elif (command[0] == 6):
    ids = list(command[2])
  else:
   ids.append(command)
 return ids

def parse_m2m ( commands ) : ids = [ ] for command in commands : if isinstance ( command , ( tuple , list ) ) : if ( command [ 0 ] in ( 1 , 4 ) ) : ids . append ( command [ 1 ] ) elif ( command [ 0 ] == 5 ) : ids = [ ] elif ( command [ 0 ] == 6 ) : ids = list ( command [ 2 ] ) else : ids . append ( command ) return ids
return a list of ids corresponding to a many2many value .