I am new to python, django. What I'm trying to do is that I have a model defined as products that has two columns: name and price.
name price
pen 20
paper 30
eraser 0
I am trying to sort them using the following code:
Product.objects.all().order_by('-price')
This sorts the values as 0,20,30
.
Model code
class Product(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
price = models.IntegerField('Price', blank=True, null=True)
What I'm trying to achieve is to sort it as 20,30,0
with the addition of 0 at the end.
Is there any function with which I can achieve it?
source
share