﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
14018	Introduce class_plural %-substitution placeholder for related_name of ForeignKey/ManyToManyField	Xiao Di Guan	nobody	"Django 1.2 [http://docs.djangoproject.com/en/dev/topics/db/models/#be-careful-with-related-name introduced] two %-substitution placeholders, `%(class)s` and `%(app_label)s`, to work around uniqueness issues when a custom `related_name` for a `ForeignKey` or `ManyToManyField` defined in an abstract base class is inherited by multiple child classes.

Quoting from [http://docs.djangoproject.com/en/dev/topics/db/models/#many-to-many-relationships Django's models documentation], ""''It's suggested ![...] that the name of a `ManyToManyField` ![...] be a plural describing the set of related model objects.''"" Given the nature of a `ManyToManyField`, it may be preferable to reciprocate this pluralized field naming style through `related_name`. By introducing a third %-substitution placeholder, `%(class_plural)s`, this can be accomplished.

Consider the following snippet:

{{{
#!python

class Tag(models.Model):
    slug = models.SlugField(max_length=63, unique=True)

class Post(models.Model):
    slug = models.SlugField(max_length=127, unique=True)
    tags = models.ManyToManyField(Tag, related_name='%(class_plural)s') # docs suggest related_name='%(app_label)s_%(class)s_related'
    
    class Meta:
        abstract = True

class Entry(Post):
    title = models.CharField(max_length=255)
    content = models.TextField()
    
    class Meta:
        verbose_name_plural = 'entries'

class Event(Post):
    summary = models.CharField(max_length=255)
    start_date = models.DateTimeField()
}}}

Arguably, `tag.entries` and `tag.events` are more semantic than either `tag.entry_set` and `tag.event_set` or `tag.appname_entry_related` and `tag.appname_event_related`.

Ultimately, the introduction of a `%(class_plural)s` %-substitution placeholder provides greater flexibility when designing models with abstract base classes and ForeignKeys or ManyToManyFields."	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix	related_name, ManyToManyField, ForeignKey, abstract base class		Design decision needed	1	0	0	1	0	0
