Reputation: 1390
For instance I have a model like so:
class Record(models.Model):
name = CharField(...)
price = IntegerField(...)
year = IntegerField(...)
How can I find the minimum or maximum of year without using a for, or while iterator?
Upvotes: 3
Views: 5383
Reputation: 15310
This doc is about how aggregation works in Django. For instance, for your Record
model class you can compute the min
and max
value for price
attribute using the following syntax:
from django.db.models import Min, Max
Record.objects.annotate(Min("price"), Max("price"))
Upvotes: 9