Ticket #25226: arrayfield-set-model-on-base-field.diff

File arrayfield-set-model-on-base-field.diff, 1.4 KB (added by Ion Scerbatiuc, 9 years ago)

The proposed fix

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

    diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py
    index 9daea8e..27c369d 100644
    a b class ArrayField(Field):  
    2828            self.default_validators.append(ArrayMaxLengthValidator(self.size))
    2929        super(ArrayField, self).__init__(**kwargs)
    3030
     31    def contribute_to_class(self, cls, name, **kwargs):
     32        super(ArrayField, self).contribute_to_class(cls, name, **kwargs)
     33        self.base_field.model = cls
     34
    3135    def check(self, **kwargs):
    3236        errors = super(ArrayField, self).check(**kwargs)
    3337        if self.base_field.remote_field:
  • tests/postgres_tests/test_array.py

    diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py
    index d152f76..d382d6d 100644
    a b class TestSaveLoad(PostgreSQLTestCase):  
    9797        self.assertEqual(instance.uuids, loaded.uuids)
    9898        self.assertEqual(instance.decimals, loaded.decimals)
    9999
     100    def test_model_is_set_on_base_field_too(self):
     101        instance = IntegerArrayModel()
     102
     103        field = instance._meta.get_field('field')
     104        self.assertEqual(field.model, IntegerArrayModel)
     105        self.assertEqual(field.base_field.model, IntegerArrayModel)
     106
    100107
    101108class TestQuerying(PostgreSQLTestCase):
    102109
Back to Top