Ticket #25953: arrayfield_condtionally_add_from_db_value.diff

File arrayfield_condtionally_add_from_db_value.diff, 878 bytes (added by Karan Lyons, 9 years ago)

Patch: Conditionally add from_db_value() to ArrayField instances.

  • django/contrib/postgres/fields/array.py

     
    2828            self.default_validators = self.default_validators[:]
    2929            self.default_validators.append(ArrayMaxLengthValidator(self.size))
    3030        super(ArrayField, self).__init__(**kwargs)
     31        if hasattr(self.base_field, 'from_db_value'):
     32            import types
     33            def from_db_value(self, value, expression, connection, context):
     34                return [self.base_field.from_db_value(i, expression, connection, context) for i in value]
     35           
     36            self.from_db_value = types.MethodType(from_db_value, self)
    3137
    3238    def contribute_to_class(self, cls, name, **kwargs):
    3339        super(ArrayField, self).contribute_to_class(cls, name, **kwargs)
Back to Top