Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.0.X] Fixed #11311 -- Reverted [10952], Refs #10785. Changeset [109…

…52] caused problems with m2m relations between models that had non-integer primary keys. Thanks to Ronny for the report and test case.

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.0.X@11008 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 8656fffbe0d30c35a7415f8b5928d06ff93e8cc3 1 parent 1ff9ec9
Russell Keith-Magee authored June 15, 2009
14  django/db/models/fields/related.py
@@ -132,13 +132,13 @@ def pk_trace(value):
13  tests/modeltests/custom_pk/models.py
@@ -136,11 +136,14 @@ class Foo(models.Model):
136 136
 # Regression for #10785 -- Custom fields can be used for primary keys.
137 137
 >>> new_bar = Bar.objects.create()
138 138
 >>> new_foo = Foo.objects.create(bar=new_bar)
139  
->>> f = Foo.objects.get(bar=new_bar.pk)
140  
->>> f == new_foo
141  
-True
142  
->>> f.bar == new_bar
143  
-True
  139
+
  140
+# FIXME: This still doesn't work, but will require some changes in
  141
+# get_db_prep_lookup to fix it.
  142
+# >>> f = Foo.objects.get(bar=new_bar.pk)
  143
+# >>> f == new_foo
  144
+# True
  145
+# >>> f.bar == new_bar
  146
+# True
144 147
 
145 148
 >>> f = Foo.objects.get(bar=new_bar)
146 149
 >>> f == new_foo
14  tests/regressiontests/m2m_regress/models.py
@@ -33,6 +33,14 @@ class SelfReferChild(SelfRefer):
33 33
 class SelfReferChildSibling(SelfRefer):
34 34
     pass
35 35
 
  36
+# Many-to-Many relation between models, where one of the PK's isn't an Autofield
  37
+class Line(models.Model):
  38
+    name = models.CharField(max_length=100)
  39
+
  40
+class Worksheet(models.Model):
  41
+    id = models.CharField(primary_key=True, max_length=100)
  42
+    lines = models.ManyToManyField(Line, blank=True, null=True)
  43
+
36 44
 __test__ = {"regressions": """
37 45
 # Multiple m2m references to the same model or a different model must be
38 46
 # distinguished when accessing the relations through an instance attribute.
@@ -79,5 +87,11 @@ class SelfReferChildSibling(SelfRefer):
79 87
 >>> sr_sibling.related.all()
80 88
 [<SelfRefer: Hanna>]
81 89
 
  90
+# Regression for #11311 - The primary key for models in a m2m relation
  91
+# doesn't have to be an AutoField
  92
+>>> w = Worksheet(id='abc')
  93
+>>> w.save()
  94
+>>> w.delete()
  95
+
82 96
 """
83 97
 }

0 notes on commit 8656fff

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