assigning new materials to mesh tessfaces blender 2.6

i’m admittingly new to blender and i’m trying to make a mesh in python.
everything is fine except a can’t seem to assign mutliple materials to different faces on my mesh.
I tried running this snippit i found here:
changing “faces” to “tessfaces” and everything seems to work. but when you toggle between edit / object mode again, all of the materials revert back to just red.
i’m guessing that there’s a completely different way to do it in 2.6 but after searching for a while i still haven’t found anything.

I wrote some code to illustrate this further:

import bpy

def new_material():
def newMaterialToFace(faceIndex, colorVal):
    newMaterial = new_material() = "m%i" % faceIndex
    newMaterial.use_shadeless = True
    newMaterial.diffuse_color = colorVal
    objectMesh.tessfaces[faceIndex].material_index = len(objectMesh.materials) - 1

objectRef =
objectMesh =
newMaterialToFace(0, (1, 0, 0))
newMaterialToFace(1, (0, 1, 0))

start out with a mesh selected with at least two faces and you should see my problem. the green face reverts back to red when you toggle between modes or when you uncomment that last line. is there a different update mode i should be calling to have my tessfaces’ material_index info saved?