diff options
| author | Alex Hill <alex@hill.net.au> | 2015-03-27 00:52:11 +0800 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-08-27 09:20:17 -0400 |
| commit | 7bec480fe2ace94c8e7f0c88485442bfa74436b4 (patch) | |
| tree | dcc410f3c9af85b752d477be4e18ecd1f3074520 /tests/contenttypes_tests | |
| parent | e1427cc609fa6ab247501b101cfb3c0092aba55b (diff) | |
Fixed #24201 -- Added order_with_respect_to support to GenericForeignKey.
Diffstat (limited to 'tests/contenttypes_tests')
| -rw-r--r-- | tests/contenttypes_tests/models.py | 39 | ||||
| -rw-r--r-- | tests/contenttypes_tests/test_order_with_respect_to.py | 18 |
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py index 88b926fce6..a302fe97f0 100644 --- a/tests/contenttypes_tests/models.py +++ b/tests/contenttypes_tests/models.py @@ -1,5 +1,9 @@ from __future__ import unicode_literals +from django.contrib.contenttypes.fields import ( + GenericForeignKey, GenericRelation, +) +from django.contrib.contenttypes.models import ContentType from django.db import models from django.utils.encoding import python_2_unicode_compatible from django.utils.http import urlquote @@ -76,3 +80,38 @@ class FooWithBrokenAbsoluteUrl(FooWithoutUrl): def get_absolute_url(self): return "/users/%s/" % self.unknown_field + + +class Question(models.Model): + text = models.CharField(max_length=200) + answer_set = GenericRelation('Answer') + + +@python_2_unicode_compatible +class Answer(models.Model): + text = models.CharField(max_length=200) + content_type = models.ForeignKey(ContentType, models.CASCADE) + object_id = models.PositiveIntegerField() + question = GenericForeignKey() + + class Meta: + order_with_respect_to = 'question' + + def __str__(self): + return self.text + + +@python_2_unicode_compatible +class Post(models.Model): + """An ordered tag on an item.""" + title = models.CharField(max_length=200) + content_type = models.ForeignKey(ContentType, models.CASCADE, null=True) + object_id = models.PositiveIntegerField(null=True) + parent = GenericForeignKey() + children = GenericRelation('Post') + + class Meta: + order_with_respect_to = 'parent' + + def __str__(self): + return self.title diff --git a/tests/contenttypes_tests/test_order_with_respect_to.py b/tests/contenttypes_tests/test_order_with_respect_to.py new file mode 100644 index 0000000000..5d7f99d48b --- /dev/null +++ b/tests/contenttypes_tests/test_order_with_respect_to.py @@ -0,0 +1,18 @@ +from order_with_respect_to.tests import ( + OrderWithRespectToTests, OrderWithRespectToTests2, +) + +from .models import Answer, Post, Question + + +class OrderWithRespectToGFKTests(OrderWithRespectToTests): + Answer = Answer + Question = Question + +del OrderWithRespectToTests + + +class OrderWithRespectToGFKTests2(OrderWithRespectToTests2): + Post = Post + +del OrderWithRespectToTests2 |
