如何在PyMODM模型类中定义初始化器

时间:2019-05-08 16:27:51

标签: python python-3.x pymongo pymodm

我想为我的PyMODM类提供一个自定义的初始化程序。直接做到

class MyModel(MongoModel):
    fields = ...
    def __init__(self, other_args...):
        super().__init__(other_args)
        do_something_else()

首先产生警告:

DeprecationWarning: __class__ not set defining 'MyModel' as <class '__main__.MyModel'>. Was __classcell__ propagated to type.__new__?

,然后出现错误:

TypeError: __init__() missing required positional arguments

我想念什么?

1 个答案:

答案 0 :(得分:0)

我这样做:

class MyModel(MongoModel):
fields = ...
def __init__(self, other_args...):
    super(MyModel, self).__init__(other_args)
    do_something_else()

有效,但我得到DeprecationWarning: __class__ not set defining...

Provide __classcell__ example for Python 3.6 metaclass在这里他们解释得更多,但我一点也不理解