mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
Fixed #25143 -- Added ArrayField.from_db_value().
Thanks Karan Lyons for contributing to the patch.
This commit is contained in:
committed by
Tim Graham
parent
f8d20da047
commit
2495023a4c
@@ -28,6 +28,10 @@ class ArrayField(Field):
|
||||
if self.size:
|
||||
self.default_validators = self.default_validators[:]
|
||||
self.default_validators.append(ArrayMaxLengthValidator(self.size))
|
||||
# For performance, only add a from_db_value() method if the base field
|
||||
# implements it.
|
||||
if hasattr(self.base_field, 'from_db_value'):
|
||||
self.from_db_value = self._from_db_value
|
||||
super(ArrayField, self).__init__(**kwargs)
|
||||
|
||||
@property
|
||||
@@ -100,6 +104,14 @@ class ArrayField(Field):
|
||||
value = [self.base_field.to_python(val) for val in vals]
|
||||
return value
|
||||
|
||||
def _from_db_value(self, value, expression, connection, context):
|
||||
if value is None:
|
||||
return value
|
||||
return [
|
||||
self.base_field.from_db_value(item, expression, connection, context)
|
||||
for item in value
|
||||
]
|
||||
|
||||
def value_to_string(self, obj):
|
||||
values = []
|
||||
vals = self.value_from_object(obj)
|
||||
|
||||
Reference in New Issue
Block a user