I am currently working with Flask, Flask-SQLAchlemy and Flask-Restless to provide endpoints for an AngularJS backend application. I have set up the necessary many to many relationships between tables thanks to another user.
I have a new issue, which is that I have to set the count
column in my junction table. In addition, I also have to increment count
by 1. I have been looking through the Flask Restless Docs to find a solution, but I haven't seen any reference to accessing a junction table column. I have also tried accessing it through include columns
without success. Here are my involved tables:
surveyOptions = db.Table('survey_options',
db.Column('survey_id', db.Integer, db.ForeignKey('survey.id')),
db.Column('option_id', db.Integer, db.ForeignKey('option.id')),
db.Column('count', db.Integer) # increment this value
)
class Survey(db.Model):
id = db.Column(db.Integer, primary_key=True)
category = db.Column(db.String(50))
question = db.Column(db.Text)
startDate = db.Column(db.DateTime)
endDate = db.Column(db.DateTime)
options = db.relationship('Option', secondary=surveyOptions,
backref=db.backref('surveys', lazy='dynamic'), lazy='dynamic')
class Option(db.Model):
id = db.Column(db.Integer, primary_key=True)
text = db.Column(db.Text)
Any guidance on how to increment the surveyOptions.count
column would be greatly appreciated. I am more than willing to provide more code samples if you need any.
Edit
count
will be incremented everytime that a user selects one of the options, to keep track of how many people prefer each option