django/django — pull request #175 by adw0rd (2012-06-25 19:53:23+00:00)
Title: Added the implementation for MySQL for specifying of several fields in distinct()

Allows use of multiple distinct fields:

>>> print User.objects.distinct('username').query
SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` GROUP BY `auth_user`.`username` ORDER BY NULL

>>> print User.objects.distinct('username', 'email').query
SELECT `auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`, `auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`, `auth_user`.`is_staff`, `auth_user`.`is_active`, `auth_user`.`is_superuser`, `auth_user`.`last_login`, `auth_user`.`date_joined` FROM `auth_user` GROUP BY `auth_user`.`username`, `auth_user`.`email` ORDER BY NULL

>>> print Comment.objects.distinct('comment', 'site__name').query
SELECT `django_comments`.`id`, `django_comments`.`content_type_id`, `django_comments`.`object_pk`, `django_comments`.`site_id`, `django_comments`.`user_id`, `django_comments`.`user_name`, `django_comments`.`user_email`, `django_comments`.`user_url`, `django_comments`.`comment`, `django_comments`.`submit_date`, `django_comments`.`ip_address`, `django_comments`.`is_public`, `django_comments`.`is_removed` FROM `django_comments` INNER JOIN `django_site` ON (`django_comments`.`site_id` = `django_site`.`id`) GROUP BY `django_comments`.`comment`, `django_site`.`name` ORDER BY `django_comments`.`submit_date` ASC

Russian conversation topic: http://pyha.ru/forum/topic/7913