Code

Ticket #5373: 5373.4.diff

File 5373.4.diff, 1.1 KB (added by datakid, 4 years ago)

Patch, version 4

Line 
1Index: django/db/models/fields/related.py
2===================================================================
3--- django/db/models/fields/related.py  (revision 13428)
4+++ django/db/models/fields/related.py  (working copy)
5@@ -111,7 +111,14 @@
6 
7     def set_attributes_from_rel(self):
8         self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name)
9-        if self.verbose_name is None:
10+        # self.verbose_name is also set in __init__.py
11+        # We need to check the verbose_name if __init__ has merely used the field name
12+        # but not if verbose_name is set at declaration of the field
13+        # ie foo = ForeignKey(Bar, verbose_name="this is not over-ridden")
14+        # but self.verbose_name = bar is overridden if Bar has Meta: verbose_name != ("bar"|"")
15+        if self.verbose_name is None or \
16+        ((self.verbose_name == self.name.replace('_', ' ')) and \
17+        (self.verbose_name != self.rel.to._meta.verbose_name)):
18             self.verbose_name = self.rel.to._meta.verbose_name
19         self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name
20