Fixed #29682 -- Fixed admin change form crash if a view-only model's form has an extra field.

This commit is contained in:
Tim Graham 2018-08-18 16:15:18 -04:00
parent 0e7a9525ba
commit d311124be5
6 changed files with 36 additions and 3 deletions

View file

@ -286,6 +286,22 @@ class UtilsTests(SimpleTestCase):
("not Really the Model", MockModelAdmin.test_from_model)
)
def test_label_for_field_form_argument(self):
class ArticleForm(forms.ModelForm):
extra_form_field = forms.BooleanField()
class Meta:
fields = '__all__'
model = Article
self.assertEqual(
label_for_field('extra_form_field', Article, form=ArticleForm()),
'Extra form field'
)
msg = "Unable to lookup 'nonexistent' on Article or ArticleForm"
with self.assertRaisesMessage(AttributeError, msg):
label_for_field('nonexistent', Article, form=ArticleForm()),
def test_label_for_property(self):
# NOTE: cannot use @property decorator, because of
# AttributeError: 'property' object has no attribute 'short_description'