Ticket #13328: patch_v2_13328.diff

File patch_v2_13328.diff, 1.1 KB (added by vbabiy, 11 years ago)

Second version of my patch

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

    diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
    index 281963f..7b8c65e 100644
    a b class Field(object): 
    132132        memodict[id(self)] = obj
    133133        return obj
    134134
     135    def __getstate__(self):
     136        obj_dict = self.__dict__.copy()
     137        obj_dict['default'] = None
     138        return obj_dict
     139
     140    def __setstate__(self, data):
     141        self.__dict__.update(data)
     142
     143        # Restore the default
     144        for field in self._model._meta.fields:
     145            if self.name == field.name:
     146                self.default = field.default
     147
     148
    135149    def to_python(self, value):
    136150        """
    137151        Converts the input value into the expected Python data type, raising
    class Field(object): 
    233247
    234248    def contribute_to_class(self, cls, name):
    235249        self.set_attributes_from_name(name)
     250        self._model = cls
    236251        cls._meta.add_field(self)
    237252        if self.choices:
    238253            setattr(cls, 'get_%s_display' % self.name, curry(cls._get_FIELD_display, field=self))
Back to Top