Django

Code

Changeset 2571

Show
Ignore:
Timestamp:
03/27/06 17:20:59 (3 years ago)
Author:
adrian
Message:

magic-removal: Fixed Option.verbose_name_plural behavior so that it's always calculated based on verbose_name, regardless of whether a custom verbose_name was given. Thanks for reporting, ChaosKCW

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/magic-removal/django/db/models/options.py

    r2570 r2571  
    1111get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip() 
    1212 
    13 DEFAULT_NAMES = ('verbose_name', 'verbose_name_plural', 'db_table', 'ordering', 
     13DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering', 
    1414                 'unique_together', 'permissions', 'get_latest_by', 
    1515                 'order_with_respect_to', 'app_label') 
     
    3636    def contribute_to_class(self, cls, name): 
    3737        cls._meta = self 
     38        # First, construct the default values for these options. 
    3839        self.object_name = cls.__name__ 
    3940        self.module_name = self.object_name.lower() 
    40         # If the verbose_name wasn't given, use the class name, 
    41         # converted from "InitialCaps" to "lowercase with spaces". 
    4241        self.verbose_name = get_verbose_name(self.object_name) 
    43         self.verbose_name_plural = self.verbose_name + 's' 
     42        # Next, apply any overridden values from 'class Meta'. 
    4443        if self.meta: 
    4544            meta_attrs = self.meta.__dict__ 
     
    4847            for attr_name in DEFAULT_NAMES: 
    4948                setattr(self, attr_name, meta_attrs.pop(attr_name, getattr(self, attr_name))) 
     49            # verbose_name_plural is a special case because it uses a 's' 
     50            # by default. 
     51            setattr(self, 'verbose_name_plural', meta_attrs.pop('verbose_name_plural', self.verbose_name + 's')) 
     52            # Any leftover attributes must be invalid. 
    5053            if meta_attrs != {}: 
    5154                raise TypeError, "'class Meta' got invalid attribute(s): %s" % ','.join(meta_attrs.keys())