I am new to Flask and SQLalchmey. I am trying to crate two tables and establish a manytoone relationship between them.
Here is what I did.
table_hub
class Hub(db.Model):
__tablename__ = 'hub'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(),nullable=False,unique=True)
tbl_vehicle
class vehileMaster(db.Model):
__tablename__ = 'res.vehicle'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String, nullable=False)
hub_id = db.Column(db.Integer,db.ForeignKey('hub.id'))
hub = db.relationship('Hub')
Here is what I need to achieve,
- while creating a new vehicle in table
res.vehicleI need to choose a hub from the list of hubs.
I don't know whether what i already did is correct or not.