mirror of
https://github.com/django/django.git
synced 2025-10-30 09:06:13 +00:00
Added support for modifying the effect of `DISTINCT` clauses so they
only consider some fields (PostgreSQL only). For this, the ``distinct()`` QuerySet method now accepts an optional list of model fields names and generates ``DISTINCT ON`` clauses on these cases. Thanks Jeffrey Gelens and Anssi Kääriäinen for their work. Fixes #6422. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17244 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
39
tests/modeltests/distinct_on_fields/models.py
Normal file
39
tests/modeltests/distinct_on_fields/models.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from django.db import models
|
||||
|
||||
class Tag(models.Model):
|
||||
name = models.CharField(max_length=10)
|
||||
parent = models.ForeignKey('self', blank=True, null=True,
|
||||
related_name='children')
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class Celebrity(models.Model):
|
||||
name = models.CharField("Name", max_length=20)
|
||||
greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class Fan(models.Model):
|
||||
fan_of = models.ForeignKey(Celebrity)
|
||||
|
||||
class Staff(models.Model):
|
||||
id = models.IntegerField(primary_key=True)
|
||||
name = models.CharField(max_length=50)
|
||||
organisation = models.CharField(max_length=100)
|
||||
tags = models.ManyToManyField(Tag, through='StaffTag')
|
||||
coworkers = models.ManyToManyField('self')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
|
||||
class StaffTag(models.Model):
|
||||
staff = models.ForeignKey(Staff)
|
||||
tag = models.ForeignKey(Tag)
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s -> %s" % (self.tag, self.staff)
|
||||
Reference in New Issue
Block a user