Get the number of rows in a database

How is it possible to get the number of rows from a database?

If I use this sentence:


But my question is: Is it an optimized way to do it? Because I am fetching the entire base order to see its number of rows

This is the model:

class order (models.Model):
    STATUS = [

    client = models.ForeignKey(client, on_delete=models.CASCADE)
    proveedor = models.ForeignKey (Proveedor, on_delete=models.CASCADE)
    ticket =  models.IntegerField()
    status = models.CharField(max_length=2,choices= STATUS,default= "SO")
    location_lat = models.FloatField()
    location_long = models.FloatField()
    day = models.DateField()
    time = models.TimeField()
    problem_description = models.TextField()
    picture1=models.ImageField(default=None, blank=True)

See the count() method.

1 Like