mirror of
				https://github.com/django/django.git
				synced 2025-10-31 01:25:32 +00:00 
			
		
		
		
	[1.6.x] Fixed #23282 -- Corrected inheritance and reverse relations example.
Thanks knowledgepoint-devs for the report and claudep for review.
Backport of 7006187064 from master
			
			
This commit is contained in:
		| @@ -1044,19 +1044,27 @@ as in the above example. However, this uses up the name that is the | |||||||
| default :attr:`~django.db.models.ForeignKey.related_name` value for | default :attr:`~django.db.models.ForeignKey.related_name` value for | ||||||
| :class:`~django.db.models.ForeignKey` and | :class:`~django.db.models.ForeignKey` and | ||||||
| :class:`~django.db.models.ManyToManyField` relations.  If you | :class:`~django.db.models.ManyToManyField` relations.  If you | ||||||
| are putting those types of relations on a subclass of another model, | are putting those types of relations on a subclass of the parent model, you | ||||||
| you **must** specify the | **must** specify the :attr:`~django.db.models.ForeignKey.related_name` | ||||||
| :attr:`~django.db.models.ForeignKey.related_name` attribute on each | attribute on each such field. If you forget, Django will raise a validation | ||||||
| such field. If you forget, Django will raise an error when you run | error. | ||||||
| :djadmin:`validate` or :djadmin:`syncdb`. |  | ||||||
|  |  | ||||||
| For example, using the above ``Place`` class again, let's create another | For example, using the above ``Place`` class again, let's create another | ||||||
| subclass with a :class:`~django.db.models.ManyToManyField`:: | subclass with a :class:`~django.db.models.ManyToManyField`:: | ||||||
|  |  | ||||||
|     class Supplier(Place): |     class Supplier(Place): | ||||||
|         # Must specify related_name on all relations. |         customers = models.ManyToManyField(Place) | ||||||
|         customers = models.ManyToManyField(Restaurant, related_name='provider') |  | ||||||
|  |  | ||||||
|  | This results in the error:: | ||||||
|  |  | ||||||
|  |     Reverse query name for 'Supplier.customers' clashes with reverse query | ||||||
|  |     name for 'Supplier.place_ptr'. | ||||||
|  |  | ||||||
|  |     HINT: Add or change a related_name argument to the definition for | ||||||
|  |     'Supplier.customers' or 'Supplier.place_ptr'. | ||||||
|  |  | ||||||
|  | Adding ``related_name`` to the ``customers`` field as follows would resolve the | ||||||
|  | error: ``models.ManyToManyField(Place, related_name='provider')``. | ||||||
|  |  | ||||||
| Specifying the parent link field | Specifying the parent link field | ||||||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user