Advertisement
abrar1

Untitled

Dec 11th, 2020
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. def sort_descending(request):
  2.     sql = "select * from PRODUCT_SPECIFICATION order by PRICE desc;"
  3.     cursor = connection.cursor()
  4.     cursor.execute(sql)
  5.     result_search = cursor.fetchall()
  6.     cursor.close()
  7.     print(result_search)
  8.     table = []
  9.     for i in result_search:
  10.         product_id = i[0]
  11.         name = i[1]
  12.         type = i[2]
  13.         price = i[3]
  14.         stock = i[4]
  15.         warranty = i[5]
  16.         row = {'product_id': product_id, 'name': name, 'type': type, 'warranty': warranty, 'price': price}
  17.         table.append(row)
  18.     print(table)
  19.     return render(request, 'home.html', {'table': table})
  20.  
  21.  
  22. def sort_ascending(request):
  23.     sql = "select * from PRODUCT_SPECIFICATION order by PRICE asc;"
  24.     cursor = connection.cursor()
  25.     cursor.execute(sql)
  26.     result_search = cursor.fetchall()
  27.     cursor.close()
  28.     print(result_search)
  29.     table = []
  30.     for i in result_search:
  31.         product_id = i[0]
  32.         name = i[1]
  33.         type = i[2]
  34.         price = i[3]
  35.         stock = i[4]
  36.         warranty = i[5]
  37.         row = {'product_id': product_id, 'name': name, 'type': type, 'warranty': warranty, 'price': price}
  38.         table.append(row)
  39.     print(table)
  40.     return render(request, 'home.html', {'table': table})
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement