Opened 3 years ago

Closed 3 years ago

#32506 closed New feature (wontfix)

exclude = '__all__' treated as an iterable in fields_for_model

Reported by: Quentin Owned by: nobody
Component: Forms Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While exclude = '__all__' is accepted in ModelForm.Meta, the exclude parameter to forms.models.fields_for_model is assumed to be a list of field names.
This leads to the following behaviour:

class TestModel(models.Model):
    all_ = models.CharField(max_length=10)
    name  = models.CharField(max_length=10)

class TestForm(forms.ModelForm):
    full_name = forms.CharField(max_length=20)
    class Meta:
        model = TestModel
        exclude = '__all__'

f = TestForm()
assert 'name' in f.fields
assert 'full_name' in f.fields
assert 'all_' not in f.fields

The field all_ has been excluded on the grounds that 'all_' in '__all__' is True, which is probably not the intended behaviour. I would be glad to help if this issue is confirmed.
Best,
Quentin

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: wontfix
Status: newclosed
Type: BugNew feature
Version: 2.2master

ModelForm.exclude doesn't support __all__, see #19733 and related discussion. Excluding all fields is really niche IMO, I don't see a strong reason to support it.

Note: See TracTickets for help on using tickets.
Back to Top