Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 form.populate_obj problem "object has no attribute translate"
Hi I am creating a flask app using flask-wtf, I am using sqlachemy and mysql data base. I have an add function (which adds data to the data base) and an edit function (which updates the data base), the Error "object has no attribute translate" was affecting both, here is the code for the add function.
@bp.route('/timers/addtimer', methods=('GET', 'POST')) 
def addtimer():
    form = AddTimerForm()
    if form.validate_on_submit():
        timer = Timers(, heatingcircuit_name=str(,\
        flash('Congratulations, you are have a registered a new time control!')
        return redirect(url_for('timers.timers'))
    return render_template('timers/addtimer.html', title= 'add timer control',
and here is the code for the form.
class AddTimerForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    heating_circuit_id = QuerySelectField('Heatingcircuit_id', 
                    query_factory=lambda: Heatingcircuit.query.all(),
                    allow_blank=True, get_label='id')
    Boilercircuit_id = QuerySelectField('Boiler circuit', 
                    query_factory=lambda: Boilercircuit.query.all(),
                    allow_blank=True, get_label='id')
    duration = StringField('Duration in minutes', validators=[DataRequired()])
    submit = SubmitField('Register')
The "translate" error affects the "QuerySelectfield" only, all other fields are ok. to over come this error in the "addtimer" function I have added "str" in each data field, ie heatingcircuit_name=str( this has resolved the problem here, but when I want to edit the entry I get an error message, here is the code for the edittimer function;
@bp.route('/timers/edittimer', methods=['GET', 'POST']) 
@bp.route('/timers/edittimer/<int:id>', methods=('GET', 'POST')) 
def edittimer(id):
    obj = Timers.query.get(id) or Timers()
    form = AddTimerForm(request.form, obj=obj)
    if form.validate_on_submit():
        return redirect(url_for('timers.timers'))
    return render_template('timers/edittimer.html', title= 'edit timer control',
                              form=form, obj=obj)
the error message indicates that it is at the point "db.session.commit()" (the full error details can be added if needed) I believe that I need to be able to convert the "obj" into a string but I dont know how.
I need help to over come this problem otherwise I cannot update existing entries!
Warm regards
ps this was once a single function, but I have divided it up as not all the fields were being populated.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 4 463 Nov-11-2019, 05:15 PM
Last Post: nazmulfinance
  AttributeError: 'str' object has no attribute 'xpath' nazmulfinance 0 252 Nov-10-2019, 09:13 PM
Last Post: nazmulfinance
  got some problem with flask signup form. darktitan 1 300 Aug-30-2019, 06:05 AM
Last Post: aligoren
  Error object has no attribute text hcyeap 3 5,257 May-21-2019, 07:12 AM
Last Post: buran
  AttributeError: 'Response' object has no attribute 'replace' Truman 12 5,431 Mar-20-2019, 12:59 AM
Last Post: ichabod801
  AttributeError: 'dict' object has no attribute 'is_active' (PyMongo And Flask) usman 0 1,159 Nov-20-2018, 09:50 PM
Last Post: usman
  BeautifulSoup 'NoneType' object has no attribute 'text' bmccollum 9 5,116 Sep-14-2018, 12:56 PM
Last Post: bmccollum
  'ellipsis' object has no attribute 'lower' Bharath_AK 4 2,175 Mar-15-2018, 07:15 AM
Last Post: Bharath_AK
  AttributeError: 'NoneType' object has no attribute error vk7 1 3,447 Feb-02-2018, 08:36 AM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)