Order hierarchy in database


Having this simple model

class company (models.Model):
    password = models.CharField(max_length=200)
    email = models.EmailField(default=None)
    value1 = models.IntegerField(default=0)	
    value2 = models.IntegerField(default=0)
    def __str__(self):
        return self.email

It is possible to perform a database search, ordering value1 and then value2 from highest to lowest?
What I am looking for is that it orders from highest to lowest value1, and if there are several equal values โ€‹โ€‹of value1, these if it orders them from highest to lowest according to value2

Can it be the following sentence?


It should be:
proveedoresindependientes=company.objects.filter(email=email).order_by('-value1', '-value2')

See the docs for order_by.

1 Like