def bubble_sort(nts):
nts_len = len(nts)
for i in range(nts_len):
for p in range(nts_len - i - 1):
if nts[p] < nts[p+1]:
t = nts[p]
nts[p]= nts[p+1]
nts[p+1] = t
return nts
def menu(request):
products = Product.objects.all()
if request.method == "POST":
s = request.POST['select']
if s == 'Price: Low to High':
element = []
for var in products:
element.append(var)
list_items = list(element)
bb = bubble_sort(list_items)
el = list(bb)
print(el)
pro = Product.objects.filter(id__in=bb)
print(pro)
products = bb
# print(products)
How to retrieve data from database in bubble sort for objects?TypeError: '<' not supported between instances of 'Product' and 'Product'
sorted) or fetch the data from the database in the correct order.