用 type 生成的类, 要怎么导出到 xxx.py 文件中
cls = type("ClsName", (object, ), attr)
code = xxxGetSource(cls)
writeToFile(code, "moduleName/ClsName.py")
django,makemigrations 的时候,需要把 Model 的继承的父类 注册到 migrations 的文件中, 然后, 我的一些 Model 继承的类是动态生成的 譬如:
class XXXModel(GenerateCls({ .... }),
models.Model):
pass
def GenerateCls(....):
...
return type(name, bases, attr)