With these it helps If anyone put any thought into this edge-case, the reasons would most likely be a combination of consistency and performance. First of all, you generally can't evaluate the entire queryset just to get the last element without imposing a huge performance penalty. Person.objects.order_by('order').last() should get one row, not the entire table -- which could contain millions of rows. So in case of an unevaluated queryset, you need to reverse the order in SQL and get the top element. This will always suffer from the problem you describe.
people = Person.objects.order_by('order')
p1 = people.last()
p2 = people.last()
Django QuerySet.union() -or- QuerySet.raw() to Achieve Case-Insensitive Mutli-Search
fixed the issue. Will look into that further I have two models Product and Damaged. Product has quantity of an item and Damaged has the number of damaged quantity of that item. In my template list_product I have listed total quantity of each product. When I add number of damaged_quantity into the Damaged model it should be deducted from the number of total quantity in Product. I have implemented the following code. Everything works fine. The only problem I am having is if the total number of quantity in Product is equal to number of damaged_quantity from Damaged it doesn't show 0 in the template of product_list. How to solve it? , You can try like this: