summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-01 08:09:58 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-01 08:10:35 +0100
commit82f25266bfd367d5acd43f7cb502850146e9a53e (patch)
treed2b313432f4c04df12efa729ace18e405fdc33e9 /tests
parentbe4a106930e27fe6d8f172b7283e064bb07c33b5 (diff)
[4.0.x] Fixed #33547 -- Fixed error when rendering invalid inlines with readonly fields in admin.
Regression in de95c826673be9ea519acc86fd898631d1a11356. Thanks David Glenck for the report. Backport of 445b075def2c037b971518963b70ce13df5e88a2 from main
Diffstat (limited to 'tests')
-rw-r--r--tests/admin_inlines/models.py4
-rw-r--r--tests/admin_inlines/tests.py16
2 files changed, 20 insertions, 0 deletions
diff --git a/tests/admin_inlines/models.py b/tests/admin_inlines/models.py
index 47c5b91828..a8d2ee02e1 100644
--- a/tests/admin_inlines/models.py
+++ b/tests/admin_inlines/models.py
@@ -5,6 +5,7 @@ import random
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
+from django.core.exceptions import ValidationError
from django.db import models
@@ -204,6 +205,9 @@ class Question(models.Model):
text = models.CharField(max_length=40)
poll = models.ForeignKey(Poll, models.CASCADE)
+ def clean(self):
+ raise ValidationError("Always invalid model.")
+
class Novel(models.Model):
name = models.CharField(max_length=40)
diff --git a/tests/admin_inlines/tests.py b/tests/admin_inlines/tests.py
index 3bd3c881d4..f61ed1aeb2 100644
--- a/tests/admin_inlines/tests.py
+++ b/tests/admin_inlines/tests.py
@@ -241,6 +241,22 @@ class TestInline(TestDataMixin, TestCase):
# column cells
self.assertContains(response, "<p>Callable in QuestionInline</p>")
+ def test_model_error_inline_with_readonly_field(self):
+ poll = Poll.objects.create(name="Test poll")
+ data = {
+ "question_set-TOTAL_FORMS": 1,
+ "question_set-INITIAL_FORMS": 0,
+ "question_set-MAX_NUM_FORMS": 0,
+ "_save": "Save",
+ "question_set-0-text": "Question",
+ "question_set-0-poll": poll.pk,
+ }
+ response = self.client.post(
+ reverse("admin:admin_inlines_poll_change", args=(poll.pk,)),
+ data,
+ )
+ self.assertContains(response, "Always invalid model.")
+
def test_help_text(self):
"""
The inlines' model field help texts are displayed when using both the