summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-07-27 04:18:52 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-07-27 04:18:52 +0000
commit3cbe73692eb5bdd45227c5957f7bc1801974722b (patch)
treefef0baf3664d9a4f67671e28c7ef7c9cf310ca09 /tests
parentccab4b041bded4af529ca2ede4dffab0d95fb5f2 (diff)
Fixed #7778 -- Fixed a tricky case of foreign key clearing with inherited
models. Patch from James Murty. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8100 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/queries/models.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py
index 5231eac8be..4ba519a08e 100644
--- a/tests/regressiontests/queries/models.py
+++ b/tests/regressiontests/queries/models.py
@@ -190,6 +190,19 @@ class CustomPk(models.Model):
class Related(models.Model):
custom = models.ForeignKey(CustomPk)
+# An inter-related setup with a model subclass that has a nullable
+# path to another model, and a return path from that model.
+
+class Celebrity(models.Model):
+ name = models.CharField("Name", max_length=20)
+ greatest_fan = models.ForeignKey("Fan", null=True, unique=True)
+
+class TvChef(Celebrity):
+ pass
+
+class Fan(models.Model):
+ fan_of = models.ForeignKey(Celebrity)
+
__test__ = {'API_TESTS':"""
>>> t1 = Tag.objects.create(name='t1')
@@ -836,6 +849,21 @@ related via ForeignKeys.
>>> len(Note.objects.order_by('extrainfo__info').distinct())
3
+Bug #7778 - Model subclasses could not be deleted if a nullable foreign key
+relates to a model that relates back.
+
+>>> num_celebs = Celebrity.objects.count()
+>>> tvc = TvChef.objects.create(name="Huey")
+>>> Celebrity.objects.count() == num_celebs + 1
+True
+>>> f1 = Fan.objects.create(fan_of=tvc)
+>>> f2 = Fan.objects.create(fan_of=tvc)
+>>> tvc.delete()
+
+# The parent object should have been deleted as well.
+>>> Celebrity.objects.count() == num_celebs
+True
+
"""}
# In Python 2.3, exceptions raised in __len__ are swallowed (Python issue