title: Populate WTForm MultiCheckboxField with Flask-Principal Roles
body: <p>I'm working on an edit user page for my flask app, and I can't seem to figure out how to render the user's current roles like I do other variables, such as email. </p>
  
  <p>Here's my models, form, and view:</p>
  
  <pre><code>#Flask-Principal Role Model
  class Role(db.Model, RoleMixin):
      id = db.Column(db.Integer(), primary_key=True)
      name = db.Column(db.String(80), unique=True)
      description = db.Column(db.String(255))
  
      def __repr__(self):
          return '&lt;Role %r&gt;' % (self.name)
  
  #SQLALchemy User Model
  class User(db.Model, UserMixin):
      id = db.Column(db.Integer, primary_key = True)
      email = db.Column(db.String(255), unique=True)
      password = db.Column(db.String(255))
      first_name = db.Column(db.String(128))
      last_name = db.Column(db.String(128))
      business_name = db.Column(db.String(128))
      active = db.Column(db.Boolean())
      roles = db.relationship('Role', secondary=roles_users,
                              backref=db.backref('users', lazy='dynamic'))
  
  #WTForms User Form
  class UserForm(Form):
      first_name = StringField('first name', validators= [Required()])
      last_name = StringField('last name', validators= [Required()])
      business_name = StringField('business name', validators= [Required()])
      email = StringField('email', validators = [Required(), Email()])
      active = BooleanField('active')
      roles = MultiCheckboxField('roles', coerce=int)
  
  #Edit User View
  @app.route('/admin/users/&lt;id&gt;/edit/', methods = ['GET', 'POST'])
  @roles_required('admin')
  def edit_user(id):
      user = User.query.filter_by(id = id).first()
      editform = UserForm()
  
  # This is how I've assigned choices for other MultiCheckboxField forms, but I haven't 
  # needed to populate the MultiCheckboxField from a user model before with role objects.
  
      editform.roles.choices = [(x.id,x.name) for x in Role.query.all()]
  
      if editform.validate_on_submit():
          pass
  
      editform.first_name.data = user.first_name
      editform.last_name.data = user.last_name
      editform.business_name.data = user.business_name
      editform.email.data = user.email
      editform.active.data = user.active
  
  #The below doesn't show all the available roles, just the current roles assigned.
  
      editform.roles.data = user.roles
  
  
      return render_template("user_edit.html",
          title = "Edit User",
          user = user,
          editform = editform)
  </code></pre>
  
  <p>So then, does anyone know how to have WTForms display all the Roles available, and have checked the ones which are currently in the user.roles list?</p>