kvesteri / wtforms-alchemy

Tools for creating wtforms from sqlalchemy models
Other
245 stars 59 forks source link

SelectField for child entity #137

Open zjpiazza opened 5 years ago

zjpiazza commented 5 years ago

I have a data model as follows:

`class Contact(db.Model):

__tablename__ = "contact"

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
first_name = db.Column(db.String(45), nullable=False)
last_name = db.Column(db.String(45), nullable=False)
phone_number = db.Column(db.String(25), nullable=False)
email = db.Column(db.String(45), nullable=False)

def __init__(self, first_name=None, last_name=None, phone_number=None, email=None):
    self.first_name = first_name
    self.last_name = last_name
    self.phone_number = phone_number
    self.email = email

class Organization(db.Model): tablename = 'organization'

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String(45), nullable=False)
contact_id = db.Column(db.Integer, db.ForeignKey(Contact.id), nullable=False)
users = db.relationship('User', backref=db.backref('organization', lazy=True))
contacts = db.relationship('Contact', backref=db.backref('organization', lazy=True))

def __init__(self, name, contact_id):
    self.name = name
    self.contact_id = contact_id
    self.display = self.name`

When I generate a form for Organization, I am not presented with a SelectField for the Contact. The documentation is a bit lacking on this topic. Is there an easy way to achieve this functionality?