Your method load_company_by_id()
is defined as an instance method currently, while you're trying to use it as a class method. To make it a class method, you need to use classmethod
decorator:
@classmethod
def load_company_by_id(cls, id):
# Class itself is passed as the first argument.
return cls.query.get(int(id))
But why not remove this method altogether and simply call Company.query.get()
?
# Note the route (<int:id> part), not only it makes sure that id is an integer,
# it also returns an int.
@app.route('/company/edit/<int:id>', methods=['GET','POST'])
def company_edit(id):
company = Company.query.get(id)
form = CompanyForm(obj=company)
return render_template('company_form.html', form=form)