mirror of
				https://github.com/django/django.git
				synced 2025-10-30 17:16:10 +00:00 
			
		
		
		
	Fixed #10414 -- Made select_related() fail on invalid field names.
This commit is contained in:
		
				
					committed by
					
						 Tim Graham
						Tim Graham
					
				
			
			
				
	
			
			
			
						parent
						
							b27db97b23
						
					
				
				
					commit
					3daa9d60be
				
			| @@ -10,6 +10,9 @@ the select-related behavior will traverse. | ||||
| from django.db import models | ||||
| from django.utils.encoding import python_2_unicode_compatible | ||||
|  | ||||
| from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation | ||||
| from django.contrib.contenttypes.models import ContentType | ||||
|  | ||||
| # Who remembers high school biology? | ||||
|  | ||||
|  | ||||
| @@ -94,3 +97,41 @@ class HybridSpecies(models.Model): | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.name | ||||
|  | ||||
|  | ||||
| @python_2_unicode_compatible | ||||
| class Topping(models.Model): | ||||
|     name = models.CharField(max_length=30) | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.name | ||||
|  | ||||
|  | ||||
| @python_2_unicode_compatible | ||||
| class Pizza(models.Model): | ||||
|     name = models.CharField(max_length=100) | ||||
|     toppings = models.ManyToManyField(Topping) | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.name | ||||
|  | ||||
|  | ||||
| @python_2_unicode_compatible | ||||
| class TaggedItem(models.Model): | ||||
|     tag = models.CharField(max_length=30) | ||||
|  | ||||
|     content_type = models.ForeignKey(ContentType, related_name='select_related_tagged_items') | ||||
|     object_id = models.PositiveIntegerField() | ||||
|     content_object = GenericForeignKey('content_type', 'object_id') | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.tag | ||||
|  | ||||
|  | ||||
| @python_2_unicode_compatible | ||||
| class Bookmark(models.Model): | ||||
|     url = models.URLField() | ||||
|     tags = GenericRelation(TaggedItem) | ||||
|  | ||||
|     def __str__(self): | ||||
|         return self.url | ||||
|   | ||||
		Reference in New Issue
	
	Block a user