mirror of
https://github.com/django/django.git
synced 2025-07-19 03:05:32 +00:00
Fixed #17673 -- Forbid field shadowing.
Thanks Anssi Kääriäinen for the suggestion.
This commit is contained in:
parent
f5123c7291
commit
ee9fcb1672
6 changed files with 223 additions and 65 deletions
|
@ -10,7 +10,7 @@ from django.utils import six
|
|||
|
||||
from .models import (
|
||||
Chef, CommonInfo, ItalianRestaurant, ParkingLot, Place, Post,
|
||||
Restaurant, Student, StudentWorker, Supplier, Worker, MixinModel,
|
||||
Restaurant, Student, Supplier, Worker, MixinModel,
|
||||
Title, Base, SubBase)
|
||||
|
||||
|
||||
|
@ -48,38 +48,6 @@ class ModelInheritanceTests(TestCase):
|
|||
# doesn't exist as a model).
|
||||
self.assertRaises(AttributeError, lambda: CommonInfo.objects.all())
|
||||
|
||||
# A StudentWorker which does not exist is both a Student and Worker
|
||||
# which does not exist.
|
||||
self.assertRaises(
|
||||
Student.DoesNotExist,
|
||||
StudentWorker.objects.get, pk=12321321
|
||||
)
|
||||
self.assertRaises(
|
||||
Worker.DoesNotExist,
|
||||
StudentWorker.objects.get, pk=12321321
|
||||
)
|
||||
|
||||
# MultipleObjectsReturned is also inherited.
|
||||
# This is written out "long form", rather than using __init__/create()
|
||||
# because of a bug with diamond inheritance (#10808)
|
||||
sw1 = StudentWorker()
|
||||
sw1.name = "Wilma"
|
||||
sw1.age = 35
|
||||
sw1.save()
|
||||
sw2 = StudentWorker()
|
||||
sw2.name = "Betty"
|
||||
sw2.age = 24
|
||||
sw2.save()
|
||||
|
||||
self.assertRaises(
|
||||
Student.MultipleObjectsReturned,
|
||||
StudentWorker.objects.get, pk__lt=sw2.pk + 100
|
||||
)
|
||||
self.assertRaises(
|
||||
Worker.MultipleObjectsReturned,
|
||||
StudentWorker.objects.get, pk__lt=sw2.pk + 100
|
||||
)
|
||||
|
||||
def test_multiple_table(self):
|
||||
post = Post.objects.create(title="Lorem Ipsum")
|
||||
# The Post model has distinct accessors for the Comment and Link models.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue