SQLAlchemy an error when swamping the name of the database table

Viewed 44

I'm trying to show the database data when clicked on any dropdown link.

enter image description here

The HTML code:

 <input type='text' placeholder='Search...' id='products' onkeyup='filterFunction()'>
      {% product in all_products %}
        <a href='{{ url_for('home', product=product.name) }}'>{{ product.name }}</a>
      {% endfor %}

The request.args.get is send.

product

Then in main.py the request.args.get is replacing the name of the table:

@app.route('/', methods=['GET', 'POST'])
def home():
all_products = db.session.query(Product).all()     
current_product = request.args.get('product')

display_product = db.session.query(Product, current_product).join(current_product).all()

return render_template('index.html', all_products=all_products)
 

My database:

class Products(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(50))

class Product1(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
  size= db.Column(db.String(50))
  dim_a = db.Column(db.Integer)
  dim_b = db.Column(db.Integer)
  dim_c = db.Column(db.Integer)
   
class Product2(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  product_id = db.Column(db.Integer, db.ForeignKey('product.id'))
  size = db.Column(db.String(50))
  dim_a = db.Column(db.Integer)
  dim_b = db.Column(db.Integer)
  dim_c = db.Column(db.Integer)

The problem is that I'm getting an error

'sqlalchemy.exc.ArgumentError: Textual column expression 'product1' should be explicitly declared with text('product1'), or use literal_column('product1') for more specificity'

when using current_product as table name.

0 Answers
Related