如何修复sqlalchemy.exc.InterfaceError:<无法打印的InterfaceError对象>

时间:2019-12-30 20:25:12

标签: python mysql sql flask

我正在尝试提交表单,但是根据追溯, routes.py 中的db.session.commit()行未正确执行。我怎样才能解决这个问题?问题可能是由于我试图提前传递到form.attendance.data中。任何帮助将不胜感激。

routes.py

@clubs.route("/record_minutes/<int:user_id>/<int:club_id>/<int:purchase>/<int:fund>/record", methods=['GET', 'POST'])
@login_required
def record_club_minutes(user_id, club_id, purchase, fund):
    user = User.query.get_or_404(user_id)
    club = Club.query.get_or_404(club_id)
    members = club.members
    form = create_club_minutes_form(club, purchase, fund)
    purchases = ""
    funds = ""
    purchvote = ""
    fvote =""
    form.attendance.data = club.members
    if form.validate_on_submit():
            #SKIPPED CODE FOR PURCHASES & FUNDS
            minute = Minutes(club_id=club_id, date=form.date.data, time=form.time.data, location=form.location.data, attendance=form.attendance.data, purchase=purchases, purchasemotion=purchvote, fundraiser=funds, fundmotion=fvote, minute=form.notes.data)
            db.session.add(minute)
            db.session.commit()
            flash(f'Minutes successfully recorded', 'success')
            return redirect(url_for('clubs.view_club_name', user_id=user.id))
    return render_template('record_minutes.html', title='Record', form=form, user=user, club=club, members=members)

models.py

class Minutes(db.Model): 
    id = db.Column(db.Integer, primary_key=True)
    club_id = db.Column(db.Integer, db.ForeignKey('club.id'))
    date = db.Column(db.Date, nullable=False) #0000-00-00
    time = db.Column(db.String(100)) #00:00:00
    location = db.Column(db.String(100), nullable=False)
    attendance = db.Column(db.String(200)) #check code
    purchase =  db.Column(db.Text)
    purchasemotion = db.Column(db.Text)
    fundraiser = db.Column(db.Text)
    fundmotion = db.Column(db.Text)
    minute = db.Column(db.Text, nullable=False) #notes
    def __repr__(self):
        return f'{self.club_id} {self.date}'

forms.py

def create_club_minutes_form(club, purchase, fund):
    def club_user_query():
        return club.members
    class ClubMinutesForm(FlaskForm):
        date = DateField('Meeting Date (mm/dd/year)',
            validators=[DataRequired(), DateRange(max = date.today())],
            format = '%m/%d/%Y')
        time = StringField('Meeting Called to Order at')
        location = StringField('Meeting Place',
            validators=[DataRequired()],
            render_kw={"placeholder":"Room # or Area"})
        attendance = TextAreaField('Attendance')
        purchaseform = FieldList(FormField(PurchaseOrderForms), 
            min_entries=purchase, 
            max_entries=purchase)
        purchasevote = FormField(MotionForms)
        fundform = FieldList(FormField(FundraiserForms), 
            min_entries=fund, 
            max_entries=fund)
        fundvote = FormField(MotionForms)
        notes = TextAreaField('Overview of Meeting', 
            validators=[DataRequired(), Length(min=10, max=500)])
        submit = SubmitField('Submit')

    return ClubMinutesForm()

0 个答案:

没有答案