title: MongoEngine: A ReferenceField only accepts DBRef or documents when defining document_type as str
body: <p>In one MongoEngine model I'm using a reference field, when I use</p>
  <pre><code>schedule =  ReferenceField('Schedule',required=True)
  </code></pre>
  <p>and attempt to insert the document</p>
  <pre><code>#my_schedule being a 'Schedule' object that has been created and saved successfully
  record.schedule = my_schedule
  record.save()
  </code></pre>
  <p>I get</p>
  <pre><code>ValidationError: ValidationError (Calling:None) (A ReferenceField only accepts DBRef or documents: ['schedule'])
  </code></pre>
  <p>However if I change the field definition to</p>
  <pre><code>schedule =  ReferenceField(path.to.Schedule,required=True)
  </code></pre>
  <p>(I.E. directly reference the Schedule model)</p>
  <p>The document can be saved successfully. How can I avoid this error?</p>
  <p>Full defenition of the Schedule model</p>
  <pre><code>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']
      }
  </code></pre>
  <p>And for Calling</p>
  <pre><code>class Calling(Document):
      &quot;&quot;&quot;
      Calling Point
      &quot;&quot;&quot;
      
      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')]
      }
  </code></pre>
  <p>Python 2.7, MongoEngine 0.8.2, PyMongo 2.5.2</p>
  <h1>Update</h1>
  <p>As requested; Output of <code>_document_registry</code></p>
  <pre><code>{'Calling': &lt;class 'models.calling.Calling'&gt;,
   'Schedule': &lt;class 'models.schedule.Schedule'&gt;,
   'Station': &lt;class 'models.station.Station'&gt;,
   'Stop': &lt;class 'models.stop.Stop'&gt;,
   'Train': &lt;class 'models.train.Train'&gt;,
   'Update': &lt;class 'models.update.Update'&gt;}
  </code></pre>
  <p>Folder layout;</p>
  <pre><code>├── app
  │   ├── controllers
  │   ├── models
  │   └── views
  └── tasks
  </code></pre>
  <p>app/models controls all my models, this particular error is happening in tasks/update.py (imports a data file into Mongo, run as a cron-job). app/ is appended to the system path when the app loads, if that makes a difference.</p>
  <p>in app/models I have one file per model, so app/models/schedule.py contains Schedule etc.</p>
  <p>And yes, you are correct in that I have solved the problem by referencing the object directly, however doing that creates a circular dependency problem between calling.py and schedule.py, while I could move Calling and Schedule models to the same file I don't want to because I'm a stubborn programmer and like my one-model-per-file rule despite it making no real difference =)</p>
  <h1>Update 2</h1>
  <p>Adding</p>
  <pre><code>print type(my_schedule), schd, type(Schedule)
  </code></pre>
  <p>gives me</p>
  <pre><code>&lt;class 'app.models.schedule.Schedule'&gt; Schedule object &lt;class 'mongoengine.base.metaclasses.TopLevelDocumentMetaclass'&gt;
  </code></pre>