Fixed #25226 -- Set the model attribute on ArrayField's base_field

This commit is contained in:
Ion Scerbatiuc 2015-08-04 16:23:05 -07:00 committed by Tim Graham
parent 244404227e
commit 520802160a
2 changed files with 10 additions and 0 deletions

View File

@ -28,6 +28,10 @@ class ArrayField(Field):
self.default_validators.append(ArrayMaxLengthValidator(self.size)) self.default_validators.append(ArrayMaxLengthValidator(self.size))
super(ArrayField, self).__init__(**kwargs) super(ArrayField, self).__init__(**kwargs)
def contribute_to_class(self, cls, name, **kwargs):
super(ArrayField, self).contribute_to_class(cls, name, **kwargs)
self.base_field.model = cls
def check(self, **kwargs): def check(self, **kwargs):
errors = super(ArrayField, self).check(**kwargs) errors = super(ArrayField, self).check(**kwargs)
if self.base_field.remote_field: if self.base_field.remote_field:

View File

@ -97,6 +97,12 @@ class TestSaveLoad(PostgreSQLTestCase):
self.assertEqual(instance.uuids, loaded.uuids) self.assertEqual(instance.uuids, loaded.uuids)
self.assertEqual(instance.decimals, loaded.decimals) self.assertEqual(instance.decimals, loaded.decimals)
def test_model_set_on_base_field(self):
instance = IntegerArrayModel()
field = instance._meta.get_field('field')
self.assertEqual(field.model, IntegerArrayModel)
self.assertEqual(field.base_field.model, IntegerArrayModel)
class TestQuerying(PostgreSQLTestCase): class TestQuerying(PostgreSQLTestCase):