I would create a helper function (defined within this one) that does 

try:
    if role.course_id == course_id:
        role.delete()
except Role.DoesNotExist
    pass

Then you can just call that function with each role type.