In my current code with this class:
class CombinedData(db.Model):
id = db.Column(db.Integer, primary_key=True)
Product_ID = db.Column(db.Integer)
Product_Name = db.Column(db.String(100))
Product_Price = db.Column(db.Float)
Product_Company = db.Column(db.String(100))
Product_Series = db.Column(db.String(100))
Product_Type = db.Column(db.String(100))
I am trying to filter a product, when it’s price is between a range. Currently I have my range hardcoded just to make sure it actually works, so this is the current code for the filtering:
query = CombinedData.query
if price != '1':
if price == '2':
print('This should work?')
query.filter(CombinedData.Product_Price.between(1.00,2.00))
print('Filtered Query:', query)
elif price == '3':
query.filter(CombinedData.Product_Price.between(3.00,4.00))
I managed to print out ‘This should work’? so I know I actually reach that section of the code, but when I compare the initial query to the filtered query I find that they are the exact same.
querys for reference:
Initial Query: SELECT combined_data.id AS combined_data_id, combined_data.”Product_ID” AS “combined_data_Product_ID”, combined_data.”Product_Name” AS “combined_data_Product_Name”, combined_data.”Product_Price” AS “combined_data_Product_Price”, combined_data.”Product_Company” AS “combined_data_Product_Company”, combined_data.”Product_Series” AS “combined_data_Product_Series”, combined_data.”Product_Type” AS “combined_data_Product_Type”
FROM combined_data
Filtered Query: SELECT combined_data.id AS combined_data_id, combined_data.”Product_ID” AS “combined_data_Product_ID”, combined_data.”Product_Name” AS
“combined_data_Product_Name”, combined_data.”Product_Price” AS “combined_data_Product_Price”, combined_data.”Product_Company” AS “combined_data_Product_Company”, combined_data.”Product_Series” AS “combined_data_Product_Series”, combined_data.”Product_Type” AS “combined_data_Product_Type”
FROM combined_data
So far I’ve just been trying to make sure this line actually runs, and tried researching whatever I could find about the specifications of using between, because as far as I know, it’s supposed to add in a section that follows something along the lines of ‘x: BETWEEN x_1 AND x_2’ whenever some code like between(x_1,x_2), but I haven’t found much else.
person_ed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.