Skip to content
Advertisement

How can I get top 5 inventory items from a django model which has lowest quantity?

#This is my inventory model. I want to get the inventory items that have the lowest quantity in the model.

JavaScript

Advertisement

Answer

To get a number of results with the lowest or highest value you first order by that field order_by('quantity') so that the results you want will be first, then you can slice the queryset to limit the number of results

The quantity field should really be a PositiveIntegerField or IntegerField since it stores integers

JavaScript
Advertisement