Ticket #20487: 20487.diff

File 20487.diff, 3.6 KB (added by Mariusz Felisiak, 7 years ago)
  • tests/queries/models.py

    diff --git a/tests/queries/models.py b/tests/queries/models.py
    index 902fd55c05..47edb0b017 100644
    a b class CategoryItem(models.Model):  
    449449        return "category item: " + str(self.category)
    450450
    451451
     452class OtherCategoryItem(models.Model):
     453    Category = models.ForeignKey('SimpleCategory', models.CASCADE)
     454
     455
     456class CommonForeignKey(models.Model):
     457    category = models.ForeignKey(CategoryItem, models.CASCADE)
     458    other_category = models.ForeignKey(OtherCategoryItem, models.CASCADE)
     459
     460
    452461class OneToOneCategory(models.Model):
    453462    new_name = models.CharField(max_length=15)
    454463    category = models.OneToOneField(SimpleCategory, models.CASCADE)
  • tests/queries/tests.py

    diff --git a/tests/queries/tests.py b/tests/queries/tests.py
    index ec50194e3a..1c3232f795 100644
    a b from django.test.utils import CaptureQueriesContext  
    1515from .models import (
    1616    FK1, Annotation, Article, Author, BaseA, Book, CategoryItem,
    1717    CategoryRelationship, Celebrity, Channel, Chapter, Child, ChildObjectA,
    18     Classroom, Company, Cover, CustomPk, CustomPkTag, Detail, DumbCategory,
    19     Eaten, Employment, ExtraInfo, Fan, Food, Identifier, Individual, Item, Job,
    20     JobResponsibilities, Join, LeafA, LeafB, LoopX, LoopZ, ManagedModel,
    21     Member, ModelA, ModelB, ModelC, ModelD, MyObject, NamedCategory, Node,
    22     Note, NullableName, Number, ObjectA, ObjectB, ObjectC, OneToOneCategory,
    23     Order, OrderItem, Page, Paragraph, Person, Plaything, PointerA, Program,
    24     ProxyCategory, ProxyObjectA, ProxyObjectB, Ranking, Related,
    25     RelatedIndividual, RelatedObject, Report, ReportComment, ReservedName,
    26     Responsibility, School, SharedConnection, SimpleCategory, SingleObject,
    27     SpecialCategory, Staff, StaffUser, Student, Tag, Task, Teacher,
    28     Ticket21203Child, Ticket21203Parent, Ticket23605A, Ticket23605B,
    29     Ticket23605C, TvChef, Valid, X,
     18    Classroom, CommonForeignKey, Company, Cover, CustomPk, CustomPkTag, Detail,
     19    DumbCategory, Eaten, Employment, ExtraInfo, Fan, Food, Identifier,
     20    Individual, Item, Job, JobResponsibilities, Join, LeafA, LeafB, LoopX,
     21    LoopZ, ManagedModel, Member, ModelA, ModelB, ModelC, ModelD, MyObject,
     22    NamedCategory, Node, Note, NullableName, Number, ObjectA, ObjectB, ObjectC,
     23    OneToOneCategory, Order, OrderItem, OtherCategoryItem, Page, Paragraph,
     24    Person, Plaything, PointerA, Program, ProxyCategory, ProxyObjectA,
     25    ProxyObjectB, Ranking, Related, RelatedIndividual, RelatedObject, Report,
     26    ReportComment, ReservedName, Responsibility, School, SharedConnection,
     27    SimpleCategory, SingleObject, SpecialCategory, Staff, StaffUser, Student,
     28    Tag, Task, Teacher, Ticket21203Child, Ticket21203Parent, Ticket23605A,
     29    Ticket23605B, Ticket23605C, TvChef, Valid, X,
    3030)
    3131
    3232
    class Queries1Tests(TestCase):  
    11721172        with self.assertRaisesMessage(FieldError, msg):
    11731173            Tag.objects.filter(unknown_field__name='generic')
    11741174
     1175    def test_common_related_model(self):
     1176        c1 = SimpleCategory.objects.create(name='c1')
     1177        c2 = SimpleCategory.objects.create(name='c2')
     1178        category = CategoryItem.objects.create(category=c1)
     1179        other_category = OtherCategoryItem.objects.create(Category=c2)
     1180        CommonForeignKey.objects.create(category=category, other_category=other_category)
     1181        qs = CommonForeignKey.objects.values(
     1182            'category', 'other_category', 'category__category', 'other_category__Category',
     1183        )
     1184        self.assertTrue(qs[:20].exists())
     1185
    11751186
    11761187class Queries2Tests(TestCase):
    11771188    @classmethod
Back to Top