Question

This is really frustrating.

Below are my document definitions, in order to have sub-class documents inherit from a base class, I followed the suggestion here: https://groups.google.com/forum/#!topic/mongoengine-users/T8lCtGv_IYQ

models/thread.py

class Thread(object):
    meta = {
        'allow_inheritance': True
    }

models/forum.py

from models.thread import Thread
from mongoengine import Document

class ForumThread(Document, Thread):
    meta = {
        'collection': 'forum_threads'
    }

models/group.py

from models.thread import Thread
from mongoengine import Document

class GroupThread(Document, Thread):
    meta = {
        'collection': 'group_threads'
    }

I am getting the NotRegistered when attempting something of this sort;

>>> from models.forum import ForumThread
>>> print ForumThread.objects().first()
>>> NotRegistered: `Thread` has not been registered in the document registry.
            Importing the document class automatically registers it, has it
            been imported?

Any help/advice would be much appreciated.

Was it helpful?

Solution

I'm not sure Thread needs a meta, alternatively try with an abstract base class[1]

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

class ForumThread(Thread):
    meta = {
        'collection': 'forum_threads'
    }

class GroupThread(Thread):
    meta = {
        'collection': 'group_threads'
    }

[1] http://docs.mongoengine.org/guide/defining-documents.html#abstract-classes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top