Re: Select *Latest* Grade Information for every Student

2010-01-31 Thread Tomasz Zieliński
On 29 Sty, 03:16, marsanyi wrote: > The joy of annotate().  In Django 1.1 and above: > > result = Student.objects.annotate(latest = models.Max('grades__date')) > > gives you the recordset, sans test_name.  Any advances on this? > I would suggest: students = Student.objects.annotate(latest_grad

Re: Select *Latest* Grade Information for every Student

2010-01-28 Thread marsanyi
The joy of annotate(). In Django 1.1 and above: result = Student.objects.annotate(latest = models.Max('grades__date')) gives you the recordset, sans test_name. Any advances on this? On Jan 28, 1:57 pm, Michael Shepanski wrote: > Is it possible to code this scenario using the Django ORM? > > I

Re: Select *Latest* Grade Information for every Student

2010-01-28 Thread David
In SQL, this would be (and I'm winging this right now so I might be slightly off) SELECT name, address, `date`, test_name, grade FROM Student as stu LEFT JOIN Grade ON stu.id = Grade.student_id WHERE `date` >= (SELECT max(`date`) FROM Grade WHERE student_id = stu.id) ORDER BY name Unless you

Select *Latest* Grade Information for every Student

2010-01-28 Thread Michael Shepanski
Is it possible to code this scenario using the Django ORM? I have two tables: STUDENT: id, name, address GRADES: id, student_id, date, test_name, grade Each Student will have several entries in the Grades table. I am wondering if it is possible using Django's ORM to select all students along