diff options
| author | Demur Nodia <demur.nodia@gmail.com> | 2018-05-27 13:06:37 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2018-07-30 16:52:12 -0400 |
| commit | 06a11ef6ecf324db0a1530b8cca727883698f442 (patch) | |
| tree | b627c9f8f48f8f547c0ddda80e4d7cbe1c3653e1 /tests/model_formsets | |
| parent | c090ea97c1a199af13c23e83883fbb18598b49fe (diff) | |
Fixed #26819 -- Fixed BaseModelFormSet.validate_unique() "unhashable type: list" crash.
Diffstat (limited to 'tests/model_formsets')
| -rw-r--r-- | tests/model_formsets/tests.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/model_formsets/tests.py b/tests/model_formsets/tests.py index 4d00a589ce..d823a78ae8 100644 --- a/tests/model_formsets/tests.py +++ b/tests/model_formsets/tests.py @@ -1459,6 +1459,33 @@ class ModelFormsetTest(TestCase): self.assertEqual(player1.team, team) self.assertEqual(player1.name, 'Bobby') + def test_inlineformset_with_arrayfield(self): + class SimpleArrayField(forms.CharField): + """A proxy for django.contrib.postgres.forms.SimpleArrayField.""" + def to_python(self, value): + value = super().to_python(value) + return value.split(',') if value else [] + + class BookForm(forms.ModelForm): + title = SimpleArrayField() + + class Meta: + model = Book + fields = ('title',) + + BookFormSet = inlineformset_factory(Author, Book, form=BookForm) + data = { + 'book_set-TOTAL_FORMS': '3', + 'book_set-INITIAL_FORMS': '0', + 'book_set-MAX_NUM_FORMS': '', + 'book_set-0-title': 'test1,test2', + 'book_set-1-title': 'test1,test2', + 'book_set-2-title': 'test3,test4', + } + author = Author.objects.create(name='test') + formset = BookFormSet(data, instance=author) + self.assertEqual(formset.errors, [{}, {'__all__': ['Please correct the duplicate values below.']}, {}]) + def test_model_formset_with_custom_pk(self): # a formset for a Model that has a custom primary key that still needs to be # added to the formset automatically |
