| 445 | |
| 446 | |
| 447 | class BasePublicationForm(forms.ModelForm): |
| 448 | date_published = forms.CharField() |
| 449 | class Meta: |
| 450 | model = Publication |
| 451 | |
| 452 | class PublicationFormWithFields(BasePublicationForm): |
| 453 | class Meta(BasePublicationForm.Meta): |
| 454 | fields = ('title',) |
| 455 | |
| 456 | class PublicationFormWithExclude(BasePublicationForm): |
| 457 | class Meta(BasePublicationForm.Meta): |
| 458 | exclude = ('date_published',) |
| 459 | |
| 460 | class ExcludeCustomizedField(TestCase): |
| 461 | """Test excluded form customized model field is not added to form (#13971).""" |
| 462 | |
| 463 | def test_field_is_not_added(self): |
| 464 | form = PublicationFormWithFields() |
| 465 | self.assert_('title' in form.fields) |
| 466 | self.assert_('date_published' not in form.fields) |
| 467 | self.assertEqual(len(form.fields), 1) |
| 468 | |
| 469 | def test_field_is_excluded(self): |
| 470 | form = PublicationFormWithExclude() |
| 471 | self.assert_('title' in form.fields) |
| 472 | self.assert_('date_published' not in form.fields) |
| 473 | self.assertEqual(len(form.fields), 1) |
| 474 | |