如何在 Mongoengine 上创建抽象模型?

Abb*_*der 3 python django mongodb mongoengine python-2.7

我需要创建必须从其他类继承的类。我尝试将其作为结构来执行:

class A(Document):
    field_1 = ...
    field_2 = ...

class B(Document):
    field_a = ... 
    field_b = ... 

class C(A,B):
    specific_field_1 = ...
    specific_field_2 = ...

    meta = {
        'collection': 'class_c',
    }
Run Code Online (Sandbox Code Playgroud)

但我不知道决定是否符合规则。在数据库中,我不想要来自class A和 的集合class B

拜托,有人能帮我做对吗?

ale*_*cxe 5

这是一个关于如何在 mongoengine 中创建抽象模型的示例(顺便说一下,类似于 django):

class A(Document):
    meta = {
        'abstract': True
    }
    pass

class B(Document):
    meta = {
        'abstract': True
    }
    pass

class C(A, B):
    specific_field_1 = ...
    specific_field_2 = ...

    meta = {
        'collection': 'class_c',
    }
Run Code Online (Sandbox Code Playgroud)

希望有帮助。