summaryrefslogtreecommitdiff
path: root/tests/admin_inlines
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2022-03-01 08:09:58 +0100
committerGitHub <noreply@github.com>2022-03-01 08:09:58 +0100
commit445b075def2c037b971518963b70ce13df5e88a2 (patch)
treeb0031d52abd1e70d4bd360e41152476d2619ccbd /tests/admin_inlines
parent119f227aa62885f12cd7dd2558a62148d02adbb4 (diff)
downloaddjango-445b075def2c037b971518963b70ce13df5e88a2.tar.gz
Fixed #33547 -- Fixed error when rendering invalid inlines with readonly fields in admin.
Regression in de95c826673be9ea519acc86fd898631d1a11356. Thanks David Glenck for the report.
Diffstat (limited to 'tests/admin_inlines')
-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 b84faee190..9002af9933 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