Ticket #13987: 13987_fix_2_with_tests_updated.diff
File 13987_fix_2_with_tests_updated.diff, 3.0 KB (added by , 14 years ago) |
---|
-
django/db/models/options.py
119 119 # Promote the first parent link in lieu of adding yet another 120 120 # field. 121 121 field = self.parents.value_for_index(0) 122 already_created = [fld for fld in self.local_fields if fld.name == field.name] 123 if already_created: 124 field = already_created[0] 122 125 field.primary_key = True 123 126 self.setup_pk(field) 124 127 else: -
tests/regressiontests/model_inheritance_regress/tests.py
11 11 ParkingLot2, ParkingLot3, Supplier, Wholesaler, Child, SelfRefParent, 12 12 SelfRefChild, ArticleWithAuthor, M2MChild, QualityControl, DerivedM, 13 13 Person, BirthdayParty, BachelorParty, MessyBachelorParty, 14 InternalCertificationAudit )14 InternalCertificationAudit, BusStation, TrainStation) 15 15 16 16 17 17 class ModelInheritanceTest(TestCase): … … 386 386 ], 387 387 attrgetter("pk") 388 388 ) 389 390 def test_13987(self): 391 """ 392 Primary key set correctly with concrete->abstract->concrete inheritance. 393 """ 394 # Regression test for #13987: Primary key is incorrectly determined 395 # when more than one model has a concrete->abstract->concrete 396 # inheritance hierarchy. 397 self.assertEquals( 398 len([field for field in BusStation._meta.local_fields 399 if field.primary_key]), 400 1 401 ) 402 self.assertEquals( 403 len([field for field in TrainStation._meta.local_fields 404 if field.primary_key]), 405 1 406 ) 407 self.assertIs(BusStation._meta.pk.model, BusStation) 408 self.assertIs(TrainStation._meta.pk.model, TrainStation) -
tests/regressiontests/model_inheritance_regress/models.py
146 146 147 147 class MessyBachelorParty(BachelorParty): 148 148 pass 149 150 # Check concrete -> abstract -> concrete inheritance 151 class SearchableLocation(models.Model): 152 keywords = models.CharField(max_length=256) 153 154 class Station(SearchableLocation): 155 name = models.CharField(max_length=128) 156 157 class Meta: 158 abstract = True 159 160 class BusStation(Station): 161 bus_routes = models.CommaSeparatedIntegerField(max_length=128) 162 inbound = models.BooleanField() 163 164 class TrainStation(Station): 165 zone = models.IntegerField()