Opened 10 years ago

Closed 10 years ago

#11646 closed (invalid)

Use refered model.verbose_name as default

Reported by: Artem Skoretskiy Owned by: nobody
Component: contrib.admin Version: 1.1
Severity: Keywords:
Cc: Artem Skoretskiy, <tonn81@…> Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If user defined verbose_name for the model, it should be used as default for all ForeignKeys to it.


class School(models.Model):
    name = models.CharField(max_length=200,blank=True)

    class Meta:
        verbose_name = u'Школа'

class Group(models.Model):
    school = models.ForeignKey(School)
    name = models.CharField(max_length=200,blank=True)

For this schema, while editing Group the field "school" should look like "Школа". Currently it is "School"

Change History (4)

comment:1 Changed 10 years ago by Russell Keith-Magee

Resolution: invalid
Status: newclosed

Err.... no, it shouldn't. Here's why:


class Group(models.Model):

foo = models.ForeignKey(School)
bar = models.ForeignKey(School, related_name='group_bars')
name = models.CharField(max_length=200,blank=True)


The name (or verbose name) of the model you are linking to can only be used as a label in the simple case where the name of the ForiegnKey field is the same as the model that is being linked to. In any non-trivial case, the labeling needs to be determined on a case-by-base basis. Django has a way to handle this - the verbose_name argument on Field:

class Group(models.Model):
    school = models.ForeignKey(School, verbose_name="Школа")
    name = models.CharField(max_length=200,blank=True)

comment:2 Changed 10 years ago by tonnzor <tonn81@…>

Cc: Artem Skoretskiy <tonn81@…> added

Yes, it works well in "the simple case where the name of the ForeignKey field is the same as the model that is being linked to".


  1. It works well for 80% of all cases
  2. It makes more sense than providing field name as label.

The idea it to provide a better [than current] default name that still can be overwritten by user. It would remove useless actions (manually set verbose_name) to get obvious result. User entered meaning data (verbose_name) - why should we ignore it? We should use it where relevant.

In case there are many ForeignKey to the same model, we can use current naming. I.e. (pseudocode, just to get the idea):

# = "school"
# field.related_class = <class School>
# self.fields = [<field school>, <field name>]
if == field.related_class.lower() or len([f for f in self.fields if f.related_class == field.related_class]):
    label = field.related_class.verbose_name

comment:3 Changed 10 years ago by anonymous

Resolution: invalid
Status: closedreopened

see comment:2

comment:4 Changed 10 years ago by dc

Resolution: invalid
Status: reopenedclosed

Please don't reopen tickets that have been closed by a core committer. If you disagree with a decision, start a thread on django-developers.

Note: See TracTickets for help on using tickets.
Back to Top