title: sqlalchemy.orm.exc.UnmappedInstanceError on Flask WTForm
body: <p>I have the following errors while displaying related forms for entry.</p>
  
  <blockquote>
    <p>sqlalchemy.orm.exc.UnmappedInstanceError UnmappedInstanceError: Class
    'sqlalchemy.util._collections.result' is not mapped</p>
  </blockquote>
  
  <p>here is the <code>models.py</code></p>
  
  <pre><code>class Project(db.Model):
  __tablename__ = 'projects'
  id = db.Column(db.Integer, primary_key=True)
  title = db.Column(db.String(175), unique=True, nullable=False)
  description = db.Column(db.Text)
  #---------------------------
  region = db.Column(db.Integer, db.ForeignKey('regions.id'))
  district  = db.Column(db.Integer, db.ForeignKey('districts.id'))
  subdistrict  = db.Column(db.Integer, db.ForeignKey('subdistricts.id'))
  village = db.Column(db.Integer, db.ForeignKey('villages.id'))
  #------------------------------------
  baseline = db.Column(db.Text())
  performance_indicator = db.Column(db.Text)
  budget = db.Column(db.Float())
  author = db.Column(db.Integer, db.ForeignKey('users.id'))
  posted_date = db.Column(db.DateTime)
  start_date = db.Column(db.DateTime)
  est_completion = db.Column(db.DateTime)
  mark_complete = db.Column(db.Boolean, default=False)
  activities = db.relationship('Activity', backref='projects', cascade='all, delete-orphan', lazy='dynamic')
  remarks = db.relationship('Remark', backref='projects', cascade='all, delete-orphan', lazy='dynamic')
  beneficiary = db.Column(db.Integer, db.ForeignKey('beneficiaries.id'))
  sector =  db.Column(db.Integer, db.ForeignKey('sectors.id'))
  media = db.relationship('Media', secondary=projects_media, backref='projects')
  
  def __init__(self, id, title, description, baseline, performance_indicator, budget, remark, remark_author, author, posted_date, start_date, est_completion, mark_complete):
      self.id = id
      self.title = title
      self.description = description
      self.baseline = baseline
      self.performance_indicator = performance_indicator
      self.budget = budget
      self.author = author
      self.posted_date = posted_date
      self.start_date = start_date
      self.est_completion = est_completion
      self.mark_complete = mark_complete
  </code></pre>
  
  <p>the <code>forms.py</code></p>
  
  <pre><code>from flask.ext.wtf.file import FileRequired, FileAllowed, FileField
  from wtforms.ext.sqlalchemy.fields import QuerySelectField
  from project.location.models import Region, District, Subdistrict, Village
  from flask.ext.uploads import UploadSet, IMAGES, DOCUMENTS
  from flask_wtf import Form
  from wtforms.validators import DataRequired, NumberRange
  from . models import Sector, Project, Activity
  from project import db
  from project.crc.models import CrC
  from wtforms import StringField, TextAreaField, validators, SubmitField, SelectField, IntegerField, DateTimeField, \
  RadioField, BooleanField, DecimalField, DateField, FileField
  def sector_lists():
      return db.session.query(Sector.name)
  
  def region_lists():
      return db.session.query(Region.region)
  
  def district_lists():
       return db.session.query(District.district)
  
  def sub_districts():
      return db.session.query(Subdistrict.subdistrict)
  
  def villages_lists():
      return db.session.query(Village.village)
  
  def project_lists():
      return db.session.query(Project.title)
  
  def activity_lists():
      return db.session.query(Activity.title)
  
  images = UploadSet('images', IMAGES)
  
  
  class ProjectForm(Form):
      title = StringField('Project Name', validators=[DataRequired()])
      description = TextAreaField('Project Details', validators=[DataRequired()])
       sector = QuerySelectField(get_label='Service Sector', query_factory=sector_lists)
       regions = QuerySelectField(get_label='Regions', query_factory=region_lists)
       district = QuerySelectField(get_label='Regions', query_factory=district_lists)
       subdistrict = QuerySelectField(get_label='Subdistrict', query_factory=sub_districts)
       village = QuerySelectField(get_label='Village', query_factory=villages_lists)
       baseline = TextAreaField('Baseline')
       performance_indicator = TextAreaField('Performance Indicator')
       budget = DecimalField("Planned Budget, places'2'")
       started = DateTimeField('Project Started Date')
       estimated_completion = DateField('Estimated Completion date', format='%Y-%m-%d')
       completed = BooleanField('Completed?', default=False)
       media_gallery = FileField('image', validators=[
      FileRequired(),
      FileAllowed(images, "Image Only")
  ])
  </code></pre>
  
  <p>and finally my <code>views.py</code></p>
  
  <pre><code>@app.route('/add', methods=['GET', 'POST'])
  def deliverables():
      forms = ProjectForm()
      if request.method == 'POST' and forms.validate_on_submit():
          pmodel = Project(title=forms.title.data,description=forms.description.data, baseline=forms.baseline.data, performance_indicator=forms.performance_indicator.data, budget=forms.budget.data, author='mainuser', posted_date=datetime.datetime.utcnow(), start_date=forms.started.data, est_completion=forms.estimated_completion.data, mark_complete=forms.completed.data)
      db.session.add(pmodel)
      db.session.commit()
  return render_template('front/deliverables_edit.html', forms=forms)
  </code></pre>