Use stack inspection to ensure the module of a created model is that of the caller. This ensures that the class is then pickleable (assuming the caller assigns the result to a class variable).