Ticket #12769: bug12769.diff

File bug12769.diff, 1.6 KB (added by Jani Tiainen, 15 years ago)

Fix to handle verbose_name and help_text translations while pickling

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

    diff -r 70e8e4955be0 django/db/models/fields/__init__.py
    a b  
    138138            items.append((k,v))
    139139        obj_dict['_translated_keys'] = translated_keys
    140140        obj_dict['error_messages'] = dict(items)
     141       
     142        translated_items = []
     143        if isinstance(self.verbose_name, Promise):
     144            args = getattr(self.verbose_name, '_proxy____args', None)
     145            if args:
     146                obj_dict['verbose_name'] = args[0]
     147                translated_items.append('verbose_name')
     148           
     149        if isinstance(self.help_text, Promise):
     150            args = getattr(self.help_text, '_proxy____args', None)
     151            if args:
     152                obj_dict['help_text'] = args[0]
     153                translated_items.append('help_text')
     154        obj_dict['_translated_items'] = translated_items
    141155        return obj_dict
    142156
    143157    def __setstate__(self, obj_dict):
     
    145159        Unpickling support.
    146160        """
    147161        translated_keys = obj_dict.pop('_translated_keys')
     162        translated_items = obj_dict.pop('_translated_items')       
    148163        self.__dict__.update(obj_dict)
    149164        for k in translated_keys:
    150165            self.error_messages[k] = _(self.error_messages[k])
    151 
     166        for k in translated_items:
     167            self.__dict__[k] = _(self.__dict__[k])
     168           
    152169    def __cmp__(self, other):
    153170        # This is needed because bisect does not take a comparison function.
    154171        return cmp(self.creation_counter, other.creation_counter)
Back to Top