Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #2783 -- Fixed one-to-one fields to work with any primary key d…

…ata type

in the related model. Thanks, Joel Heenan.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@3846 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 4ed82677be94e98f0c3164db8bfdc7d520411526 1 parent 1fc62f0
@malcolmt malcolmt authored
View
1  AUTHORS
@@ -82,6 +82,7 @@ answer newbie questions, and generally made Django that much better:
Espen Grindhaug <http://grindhaug.org/>
Brant Harris
heckj@mac.com
+ Joel Heenan <joelh-django@planetjoel.com>
hipertracker@gmail.com
Ian Holsman <http://feh.holsman.net/>
Kieran Holland <http://www.kieranholland.com>
View
2  django/core/management.py
@@ -147,7 +147,7 @@ def _get_sql_model_create(model, known_models=set()):
table_output = []
pending_references = {}
for f in opts.fields:
- if isinstance(f, models.ForeignKey):
+ if isinstance(f, (models.ForeignKey, models.OneToOneField)):
rel_field = f.rel.get_related_field()
data_type = get_rel_data_type(rel_field)
else:
View
14 tests/modeltests/one_to_one/models.py
@@ -30,6 +30,14 @@ class Waiter(models.Model):
def __str__(self):
return "%s the waiter at %s" % (self.name, self.restaurant)
+class ManualPrimaryKey(models.Model):
+ primary_key = models.CharField(maxlength=10, primary_key=True)
+ name = models.CharField(maxlength = 50)
+
+class RelatedModel(models.Model):
+ link = models.OneToOneField(ManualPrimaryKey)
+ name = models.CharField(maxlength = 50)
+
__test__ = {'API_TESTS':"""
# Create a couple of Places.
>>> p1 = Place(name='Demon Dogs', address='944 W. Fullerton')
@@ -151,4 +159,10 @@ def __str__(self):
# Delete the restaurant; the waiter should also be removed
>>> r = Restaurant.objects.get(pk=1)
>>> r.delete()
+
+# One-to-one fields still work if you create your own primary key
+>>> o1 = ManualPrimaryKey(primary_key="abc123", name="primary")
+>>> o1.save()
+>>> o2 = RelatedModel(link=o1, name="secondary")
+>>> o2.save()
"""}

0 comments on commit 4ed8267

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