Abbasov Alexander
Abbasov Alexander

Reputation: 1938

How will create abstract model at the Mongoengine?

I need create class which must inherits from others classes. I try do this as structure as:

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',
    }

but I don't know decision is complied with the rules. At DBs I will not want collections from class A and class B.

Please, can anybody help me do it right?

Upvotes: 4

Views: 2516

Answers (1)

alecxe
alecxe

Reputation: 473893

Here's an example on how to create an abstract model in mongoengine (similar to django, by the way):

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',
    }

Hope that helps.

Upvotes: 6

Related Questions