Ticket #23282: 23282.diff

File 23282.diff, 1.7 KB (added by Tim Graham, 10 years ago)
  • docs/topics/db/models.txt

    diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
    index 682db34..c19893f 100644
    a b as in the above example. However, this uses up the name that is the  
    10661066default :attr:`~django.db.models.ForeignKey.related_name` value for
    10671067:class:`~django.db.models.ForeignKey` and
    10681068:class:`~django.db.models.ManyToManyField` relations.  If you
    1069 are putting those types of relations on a subclass of another model,
    1070 you **must** specify the
    1071 :attr:`~django.db.models.ForeignKey.related_name` attribute on each
    1072 such field. If you forget, Django will raise an error when you run
    1073 :djadmin:`check` or :djadmin:`migrate`.
     1069are putting those types of relations on a subclass of the parent model, you
     1070**must** specify the :attr:`~django.db.models.ForeignKey.related_name`
     1071attribute on each such field. If you forget, Django will raise a validation
     1072error.
    10741073
    10751074For example, using the above ``Place`` class again, let's create another
    10761075subclass with a :class:`~django.db.models.ManyToManyField`::
    10771076
    10781077    class Supplier(Place):
    1079         # Must specify related_name on all relations.
    1080         customers = models.ManyToManyField(Restaurant, related_name='provider')
     1078        customers = models.ManyToManyField(Place)
    10811079
     1080This results in the error::
     1081
     1082    Reverse query name for 'Supplier.customers' clashes with reverse query
     1083    name for 'Supplier.place_ptr'.
     1084
     1085    HINT: Add or change a related_name argument to the definition for
     1086    'Supplier.customers' or 'Supplier.place_ptr'.
     1087
     1088Adding ``related_name`` to the ``customers`` field as follows would resolve the
     1089error: ``models.ManyToManyField(Place, related_name='provider')``.
    10821090
    10831091Specifying the parent link field
    10841092~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Back to Top