Ticket #14018: changes.diff

File changes.diff, 2.5 KB (added by Xiao Di Guan, 14 years ago)

Code and documentation patch

  • django/db/models/fields/related.py

     
    9797        if not cls._meta.abstract and self.rel.related_name:
    9898            self.rel.related_name = self.rel.related_name % {
    9999                    'class': cls.__name__.lower(),
     100                    'class_plural': cls._meta.verbose_name_plural.lower().__str__(),
    100101                    'app_label': cls._meta.app_label.lower(),
    101102                }
    102103
  • docs/topics/db/models.txt

     
    874874
    875875To work around this problem, when you are using :attr:`~django.db.models.ForeignKey.related_name` in an
    876876abstract base class (only), part of the name should contain
    877 ``'%(app_label)s'`` and ``'%(class)s'``.
     877``'%(app_label)s'`` and either ``'%(class)s'`` or ``'%(class_plural)s'``.
    878878
    879879- ``'%(class)s'`` is replaced by the lower-cased name of the child class
    880880  that the field is used in.
     881- ``'%(class_plural)s'`` is replaced by the lower-case pluralized name (as
     882  defined by ``verbose_name_plural`` in the child model's inner ``Meta`` class)
     883  of the child class that the field is used in.
    881884- ``'%(app_label)s'`` is replaced by the lower-cased name of the app the child
    882885  class is contained within. Each installed application name must be unique
    883886  and the model class names within each app must also be unique, therefore the
     
    908911``common_childa_related``, whilst the reverse name of the
    909912``common.ChildB.m2m`` field will be ``common_childb_related``, and finally the
    910913reverse name of the ``rare.ChildB.m2m`` field will be ``rare_childb_related``.
    911 It is up to you how you use the ``'%(class)s'`` and ``'%(app_label)s`` portion
    912 to construct your related name, but if you forget to use it, Django will raise
    913 errors when you validate your models (or run :djadmin:`syncdb`).
     914It is up to you how you use the ``'%(class)s'`` (or ``'%(class_plural)s'``) and
     915``'%(app_label)s`` portion to construct your related name, but if you forget to
     916use it, Django will raise errors when you validate your models (or run
     917:djadmin:`syncdb`).
    914918
    915919If you don't specify a :attr:`~django.db.models.ForeignKey.related_name`
    916920attribute for a field in an abstract base class, the default reverse name will
Back to Top