title: How to populate wtform select field using mongokit/pymongo?
body: <p>I'm trying to create a SelectField using a mongodb query, but so far I haven't been successful:</p>
  
  <pre><code># forms.py in blueprint
  CATEGORIES = []
  for item in db.Terms.find():
      CATEGORIES.append((item['slug'], item['name']))
  
  
  class TermForm(Form):
      category = SelectField(
          choices=CATEGORIES,
          validators=[Optional()])
  </code></pre>
  
  <p>But I get an exception:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/one/Projects/proj/manage.py", line 14, in &lt;module&gt;
      app = create_app(os.getenv('FLASK_CONFIG') or 'default')
    File "/home/one/Projects/proj/app/__init__.py", line 27, in create_app
      from app.term.models import Term, TermCategory
    File "/home/one/Projects/proj/app/term/__init__.py", line 5, in &lt;module&gt;
      from . import views
    File "/home/one/Projects/proj/app/term/views.py", line 7, in &lt;module&gt;
      from .forms import TermForm, CategoryForm
    File "/home/one/Projects/proj/app/term/forms.py", line 48, in &lt;module&gt;
      for item in db.Terms.find():
    File "/home/one/.venv/proj/lib/python3.4/site-packages/flask_mongokit.py", line 238, in __getattr__
      self.connect()
    File "/home/one/.venv/proj/lib/python3.4/site-packages/flask_mongokit.py", line 196, in connect
      host=ctx.app.config.get('MONGODB_HOST'),
  AttributeError: 'NoneType' object has no attribute 'app'
  </code></pre>
  
  <p>If anyone could shed a little more light upon the subject, I would be very appreciative.</p>