How to model objects after grouping the Django ORM?

I need to group the directories by name, and from each group to choose the directory with the latest version. Do this:
Handbook.objects.values('name').annotate(latest_version=Max('version'))

Model

class Handbook(models.Model):
 name = models.CharField(max_length=128)
 short_name = models.CharField(max_length=32)
 description = models.CharField(max_length=255)
 version = models.CharField(max_length=16, blank=False)
 create_date = models.DateTimeField('date created', default=timezone.now)

 def __str__(self):
 return self.name

 class Meta:
 unique_together = [['name', 'version']]


The result is a sheet of dictionaries with name and version. Need model objects or dictionaries of all the fields in the model. How to do it? Query for each dictionary? (this option seems not very reasonable)
April 7th 20 at 10:49
1 answer
April 7th 20 at 10:51
It is not clear which fields of the model should be if there may be different data, and only the unique name and version. Version do a line and how to find Max() is also unclear

For example -
name = foo
short_name = foo_1
description = 'Foo description'
version = v1

the second object will

name = foo
short_name = foo_1_1
description = 'Foo description 1'
version = v2

After grouping is {"name": "foo", "version": v2} and what to take short_name and description in this case?
After grouping is {"name": "foo", "version": v2} and what to take short_name and description in this case?

As the pair name version unique, short_name and description of object with name "foo", version v2 - madeline4 commented on April 7th 20 at 10:54

Find more questions by tags DjangoORM