isebarn
isebarn

Reputation: 3950

MongoEngine (python) - Extending the document class not working

Im trying to extend the base functionality of the Document class like the following:

class DocumentExtended(Document):
    meta = {'allow_inheritance': True}


class User(DocumentExtended):
    name = StringField()


User(name="John Smith").save()

The purpose is that I want to add some extra methods to DocumentExtended (but I've omitted those for brevity)

The problem is that the document does not get saved.

If I do

class User(Document):
    name = StringField()

User(name="John Smith").save()

it does get saved so I know it should work

Is there some weird trick I need to do to be able to extend the mongoengine.Document class and be able to save the models to the database?

Upvotes: 1

Views: 424

Answers (1)

isebarn
isebarn

Reputation: 3950

After 2 hours of not understanding I finally read the docs

The DocumentExtended class must set meta = {'abstract': True}

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

Upvotes: 1

Related Questions