﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
6421	Support for 'DISTINCT ON' queries with QuerySet.distinct()	Manfred Wassmann <manolo@…>	nobody	"The patch included modifies django/db/models/query.py so that the distinct method of the !QuerySet object optionally takes variable number of field names and, if given, modifies the SQL statements generated so that 'DISTINCT ON (field,...)' is used. The incentive is to allow things like described in the following example:

{{{
class Example(models.Model):
  name = models.TextField()
  date = models. DateTimeField()
  other = models.XXX()
  ...
}}}

Now ""Example.objects.all().distinct('name').order_by('name','-date')"" will return the latest entry for each distinct name.
This can not otherwise be achieved unless resorting to plain SQL.

It should be noted that - at least in standard SQL and Postgres - if name allows NULL values, the query will return all entries for which name is NULL not only the latest as one might expect."		closed	Database layer (models, ORM)	dev		duplicate			Unreviewed	0	0	0	0	0	0
