home / django_tickets / tickets

tickets: 8620

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8620 2008-08-27 20:17:11 2014-05-24 12:12:51 2022-03-06 03:42:44.148651 Accepted closed Forms New feature Normal dev fixed ModelForm.Meta.exclude only excludes model fields, not form fields If I have a ModelForm that inherits from another form, and I define exclude and/or fields, these only affect fields on the model. I cannot use them to exclude any non-model fields that I may have added to the ancestor form. E.g.: {{{ class AForm(ModelForm): extra_non_model_field = forms.CharField() class BForm(AForm): class Meta: model = Foo exclude = ('extra_non_model_field',) # this doesn't work, due to the way ModelFormMetaclass.__new__ is written }}} Sure that's a pathological example, but there are more sensible situations in which this is an issue. Seems to me it's more intuitive to expect the exclude/fields options to affect all fields, not just model fields. A fix would be to add this at django/forms/models.py line 180: {{{ [declared_fields.pop(f) for f in declared_fields.keys() if f not in opts.fields or f in opts.exclude] }}} loic84 levity   0 1 0 0 0 0
Powered by Datasette · Queries took 0.823ms