diff options
| author | Tim Graham <timograham@gmail.com> | 2015-11-20 11:31:39 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-23 11:05:18 -0500 |
| commit | 6d9f061b07ce7aa1a9da6799b3104971ee73998b (patch) | |
| tree | 4c8b861d3d6bdb741ee56b23a82e44867f64965d /tests | |
| parent | 8f724817f3744c626923fe0bf83c48b3fceab774 (diff) | |
[1.8.x] Fixed #25786 -- Fixed set_FOO_order() crash with order_with_respect_to referencing OneToOneField pk.
Partial backport of 7bec480fe2ace94c8e7f0c88485442bfa74436b4 from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/order_with_respect_to/models.py | 16 | ||||
| -rw-r--r-- | tests/order_with_respect_to/tests.py | 12 |
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/order_with_respect_to/models.py b/tests/order_with_respect_to/models.py index 18dbd08dbc..b655d29046 100644 --- a/tests/order_with_respect_to/models.py +++ b/tests/order_with_respect_to/models.py @@ -33,3 +33,19 @@ class Post(models.Model): def __str__(self): return self.title + + +# order_with_respect_to points to a model with a OneToOneField primary key. +class Entity(models.Model): + pass + + +class Dimension(models.Model): + entity = models.OneToOneField('Entity', primary_key=True) + + +class Component(models.Model): + dimension = models.ForeignKey('Dimension') + + class Meta: + order_with_respect_to = 'dimension' diff --git a/tests/order_with_respect_to/tests.py b/tests/order_with_respect_to/tests.py index 60181cca4b..82c323b93b 100644 --- a/tests/order_with_respect_to/tests.py +++ b/tests/order_with_respect_to/tests.py @@ -5,7 +5,7 @@ from operator import attrgetter from django.db import models from django.test import TestCase -from .models import Answer, Post, Question +from .models import Answer, Dimension, Entity, Post, Question class OrderWithRespectToTests(TestCase): @@ -103,3 +103,13 @@ class OrderWithRespectToTests2(TestCase): count += 1 self.assertEqual(count, 1) + + +class TestOrderWithRespectToOneToOnePK(TestCase): + def test_set_order(self): + e = Entity.objects.create() + d = Dimension.objects.create(entity=e) + c1 = d.component_set.create() + c2 = d.component_set.create() + d.set_component_order([c1.id, c2.id]) + self.assertQuerysetEqual(d.component_set.all(), [c1.id, c2.id], attrgetter('pk')) |
