Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #1839, #2415, #2536 -- Fixed a generated name clash that was co…

…mmon in

self-referential and circular relations. A lot of community debugging went into
this fix, so thanks to bmurdock@gmail.com, Marek Kubica, ramiro, Michael
Radziej (the last two giving test cases showing the problem) and James Bennett
(who did the hard work to actually diagnose the true problem and fix it).


git-svn-id: http://code.djangoproject.com/svn/django/trunk@4676 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 43809de79db2dfd3f967f4c95bca98f8f6c75fb5 1 parent 98b2e0a
Malcolm Tredinnick authored March 08, 2007
4  django/db/models/related.py
... ...
@@ -1,7 +1,7 @@
@@ -16,7 +16,7 @@ def __init__(self, parent_model, model, field):
29  tests/regressiontests/many_to_one_regress/models.py
... ...
@@ -1,13 +1,34 @@
1 1
 from django.db import models
2 2
 
  3
+# If ticket #1578 ever slips back in, these models will not be able to be
  4
+# created (the field names being lower-cased versions of their opposite
  5
+# classes is important here).
  6
+
3 7
 class First(models.Model):
4 8
     second = models.IntegerField()
5 9
 
6 10
 class Second(models.Model):
7 11
     first = models.ForeignKey(First, related_name = 'the_first')
8 12
 
9  
-# If ticket #1578 ever slips back in, these models will not be able to be
10  
-# created (the field names being lower-cased versions of their opposite
11  
-# classes is important here).
  13
+# Protect against repetition of #1839, #2415 and #2536.
  14
+class Third(models.Model):
  15
+    name = models.CharField(maxlength=20)
  16
+    third = models.ForeignKey('self', null=True, related_name='child_set')
  17
+
  18
+class Parent(models.Model):
  19
+    name = models.CharField(maxlength=20)
  20
+    bestchild = models.ForeignKey('Child', null=True, related_name='favored_by')
  21
+
  22
+class Child(models.Model):
  23
+    name = models.CharField(maxlength=20)
  24
+    parent = models.ForeignKey(Parent)
  25
+
12 26
 
13  
-__test__ = {'API_TESTS':""}
  27
+__test__ = {'API_TESTS':"""
  28
+>>> Third.AddManipulator().save(dict(id='3', name='An example', another=None)) 
  29
+<Third: Third object>
  30
+>>> parent = Parent(name = 'fred')
  31
+>>> parent.save()
  32
+>>> Child.AddManipulator().save(dict(name='bam-bam', parent=parent.id))
  33
+<Child: Child object>
  34
+"""}

0 notes on commit 43809de

Please sign in to comment.
Something went wrong with that request. Please try again.