Re: retrieve row with maximum field value django

2015-07-24 Thread Nkansah Rexford
Thank you. This will do for my needs for now. Picking the first max value that comes at the top is fine for me. On Friday, July 24, 2015 at 4:11:18 AM UTC, James Schneider wrote: > > Use a combination of order_by('-age') and first() on your query set. > > MyModel.objects.order_by('-age').first(

Re: retrieve row with maximum field value django

2015-07-23 Thread James Schneider
Use a combination of order_by('-age') and first() on your query set. MyModel.objects.order_by('-age').first() https://docs.djangoproject.com/en/1.8/ref/models/querysets/#order-by Obviously that only pulls the "first" object even if multiple objects have that same age, so you may need additional

retrieve row with maximum field value django

2015-07-23 Thread Nkansah Rexford
Say I have a model class MyModel(models.Model) name = models.CharField(max_length=20) age = models.IntergerField() How can I find the maximum based on the 'Age' field number and retrieve that whole object? I understand aggregates allows me to find and retrieve the maximum number when gi