Suppose there is a table of artifacts from which you need to get the latest version of each artifact
ORM model is as follows:
class Artifact(models.Model):
name = models.CharField(max_length=32)
version = models.CharField(max_length=16)
Copy the code
The data in the table is as follows:
The expected query results are as follows:
ORM statement is:
Artifact.objects.order_by('name'.'-version').distinct('name')
# <QuerySet [<Artifact: Artifact object (6)>, <Artifact: Artifact object (3)>]>
Copy the code