title: Flask: populating a WTform with an SQLalchemy model with relationships
body: <p>In a Flask app I have this models.py:</p>
  
  <pre><code> class UserB(Base):
      __tablename__='users'
      id=Column(Integer, primary_key=True)
      username=Column(String(50), nullable=False, unique=True)
      address=relationship("AddressB", uselist=False, backref='user')
  
  class AddressB(Base):
      __tablename__='addresses'
      id=Column(Integer, primary_key=True)
      street= Column(String(150), nullable=True)
      ...
      user_id=Column(Integer, ForeignKey('users.id'))
  </code></pre>
  
  <p>and I'd like to populate an instance userF of UserF:</p>
  
  <pre><code>class UserF(Form):
  username = StringField(validators=[
                  ])
  street = TextField(validators=[
                  Length(min=2, max=150)
                  ])
  </code></pre>
  
  <p>with an instance userB of UserB containing data from Postgresql:</p>
  
  <pre><code>@app.route('/view_user_profile', methods=['GET', 'POST'])
  @login_required
  
  def view_user_profile():
      currentUserId=current_user.id
  
      userB=db.session.query(UserB).get(currentUserId)
  
      userF=UserF(request.form)
  
      if (request.method=='GET'):
          #I'd like to populate form with data yet in Postgresql
          userF=UserF(obj=userB)
  </code></pre>
  
  <p>but doing this way I only populate profileF with username and other data from userB but not with street and other data from addressB. Of course it'd be possible to get userB.adress.street and other addressB fields one by one, but I'd prefer to have a compact solution if possible.</p>