Code

Opened 5 years ago

Closed 5 years ago

#11646 closed (invalid)

Use refered model.verbose_name as default

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

Description

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

Example:

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"

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

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 5 years ago by tonnzor <tonn81@…>

  • Cc tonnzor, <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".

BUT:

  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):

# field.name = "school"
# field.related_class = <class School>
# self.fields = [<field school>, <field name>]
if field.name.lower() == 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 5 years ago by anonymous

  • Resolution invalid deleted
  • Status changed from closed to reopened

see comment:2

comment:4 Changed 5 years ago by dc

  • Resolution set to invalid
  • Status changed from reopened to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.