Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added test to demonstrate issue 11387 isn't there anymore.

Thanks adurdin for the report and patch. Fixes #11387.
  • Loading branch information...
commit 2ca37af621c077ab805b8fcb0fb18aef0cfe802d 1 parent c4b6659
Ramiro Morales authored February 01, 2013
9  tests/regressiontests/generic_relations_regress/models.py
@@ -6,7 +6,7 @@
6 6
 
7 7
 __all__ = ('Link', 'Place', 'Restaurant', 'Person', 'Address',
8 8
            'CharLink', 'TextLink', 'OddRelation1', 'OddRelation2',
9  
-           'Contact', 'Organization', 'Note')
  9
+           'Contact', 'Organization', 'Note', 'Company')
10 10
 
11 11
 @python_2_unicode_compatible
12 12
 class Link(models.Model):
@@ -84,3 +84,10 @@ class Organization(models.Model):
84 84
     name = models.CharField(max_length=255)
85 85
     contacts = models.ManyToManyField(Contact, related_name='organizations')
86 86
 
  87
+@python_2_unicode_compatible
  88
+class Company(models.Model):
  89
+    name = models.CharField(max_length=100)
  90
+    links = generic.GenericRelation(Link)
  91
+
  92
+    def __str__(self):
  93
+        return "Company: %s" % self.name
20  tests/regressiontests/generic_relations_regress/tests.py
@@ -2,7 +2,7 @@
2 2
 from django.test import TestCase
3 3
 
4 4
 from .models import (Address, Place, Restaurant, Link, CharLink, TextLink,
5  
-    Person, Contact, Note, Organization, OddRelation1, OddRelation2)
  5
+    Person, Contact, Note, Organization, OddRelation1, OddRelation2, Company)
6 6
 
7 7
 
8 8
 class GenericRelationTests(TestCase):
@@ -80,3 +80,21 @@ def test_join_reuse(self):
80 80
         )
81 81
         self.assertEqual(str(qs.query).count('JOIN'), 2)
82 82
 
  83
+    def test_generic_relation_ordering(self):
  84
+        """
  85
+        Test that ordering over a generic relation does not include extraneous
  86
+        duplicate results, nor excludes rows not participating in the relation.
  87
+        """
  88
+        p1 = Place.objects.create(name="South Park")
  89
+        p2 = Place.objects.create(name="The City")
  90
+        c = Company.objects.create(name="Chubby's Intl.")
  91
+        l1 = Link.objects.create(content_object=p1)
  92
+        l2 = Link.objects.create(content_object=c)
  93
+
  94
+        places = list(Place.objects.order_by('links__id'))
  95
+        def count_places(place):
  96
+            return len(filter(lambda p: p.id == place.id, places))
  97
+
  98
+        self.assertEqual(len(places), 2)
  99
+        self.assertEqual(count_places(p1), 1)
  100
+        self.assertEqual(count_places(p2), 1)

0 notes on commit 2ca37af

Please sign in to comment.
Something went wrong with that request. Please try again.