mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #29682 -- Fixed admin change form crash if a view-only model's form has an extra field.
This commit is contained in:
parent
0e7a9525ba
commit
d311124be5
6 changed files with 36 additions and 3 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue