I have a model like this:
class Foo(models.Model): date = models.DateTimeField() language = models.TextField()
And I want to group Foo by language, and then get the last in each group. I could not figure out how to use the django QuerySet API for this (to be honest, I don't know how to do this in SQL). For example:
pk | date | language ---+--------+------------------ 1 | 1:00 | python 2 | 1:30 | python/django 3 | 1:45 | haskell 4 | 2:15 | python 5 | 2:45 | haskell
I want to get something similar to this result:
{ 'python': 4, 'python/django': 2, 'haskell': 5 }
Where, perhaps, instead of numbers, these are completed Foo objects.
django django-queryset
luqui
source share