Ticket #5373: 5373.4.diff

File 5373.4.diff, 1.1 KB (added by Lachlan Musicman, 14 years ago)

Patch, version 4

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

     
    111111
    112112    def set_attributes_from_rel(self):
    113113        self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name)
    114         if self.verbose_name is None:
     114        # self.verbose_name is also set in __init__.py
     115        # We need to check the verbose_name if __init__ has merely used the field name
     116        # but not if verbose_name is set at declaration of the field
     117        # ie foo = ForeignKey(Bar, verbose_name="this is not over-ridden")
     118        # but self.verbose_name = bar is overridden if Bar has Meta: verbose_name != ("bar"|"")
     119        if self.verbose_name is None or \
     120        ((self.verbose_name == self.name.replace('_', ' ')) and \
     121        (self.verbose_name != self.rel.to._meta.verbose_name)):
    115122            self.verbose_name = self.rel.to._meta.verbose_name
    116123        self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name
    117124
Back to Top