mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #2783 -- Fixed one-to-one fields to work with any primary key data type
in the related model. Thanks, Joel Heenan. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3846 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										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> | ||||
|   | ||||
| @@ -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: | ||||
|   | ||||
| @@ -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 @@ DoesNotExist: Restaurant matching query does not exist. | ||||
| # 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() | ||||
| """} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user