In one MongoEngine model, I use the link field when I use
schedule = ReferenceField('Schedule',required=True)
and try pasting a document
I get
ValidationError: ValidationError (Calling:None) (A ReferenceField only accepts DBRef or documents: ['schedule'])
However, if I changed the field definition to
schedule = ReferenceField(path.to.Schedule,required=True)
(IE directly refers to the schedule model)
The document can be saved successfully. How can I avoid this error?
Full smoothing of the schedule model
class Schedule(Document): uid = StringField(required=True) start = DateTimeField(required=True) end = DateTimeField(required=True) days = ListField(required=True) toc = StringField(required=False) meta = { 'indexes':['uid'] }
And to call
class Calling(Document): """ Calling Point """ schedule = ReferenceField('Schedule',required=True) tiploc = StringField(required=True) calling = ListField(StringField(required=True)) arrive = IntField(required=False) depart = IntField(required=False) meta = { 'indexes':[('schedule','calling','tiploc','depart'),('schedule','tiploc')] }
Python 2.7, MongoEngine 0.8.2, PyMongo 2.5.2
Update
In accordance with the request; _document_registry output
{'Calling': <class 'models.calling.Calling'>, 'Schedule': <class 'models.schedule.Schedule'>, 'Station': <class 'models.station.Station'>, 'Stop': <class 'models.stop.Stop'>, 'Train': <class 'models.train.Train'>, 'Update': <class 'models.update.Update'>}
Folder layout;
βββ app β βββ controllers β βββ models β βββ views βββ tasks
app / models manages all my models, this particular error occurs in /update.py tasks (imports data file in Mongo, runs as cron-job). app / is added to the system path when the application loads, if that matters.
in application / models I have one file per model, so app / models / schedule.py contains Schedule, etc.
And yes, you are right that I solved the problem by accessing the object directly, however this creates a cyclical dependency problem between call.py and schedule.py, while I could move the Calling and Schedule models to the same file, which I do not want, because I am a stubborn programmer and, as a rule, a single-model for each file, despite the fact that it does not have a real difference =)
Update 2
Adding
print type(my_schedule), schd, type(Schedule)
gives me
<class 'app.models.schedule.Schedule'> Schedule object <class 'mongoengine.base.metaclasses.TopLevelDocumentMetaclass'>