Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#10949 closed (invalid)

In forms.ModelForm Meta.fields needs to be a list if only single field is defined

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

Description

The following is not working! It returns a broken form if instantiated:

class ExampleForm(forms.ModelForm):
    class Meta:
        model = ExampleModel
        fields = ('single_field')

It is working if Meta.fields is set to a list:

class ExampleForm(forms.ModelForm):
    class Meta:
        model = ExampleModel
        fields = ['single_field']

If this is intended behaviour it should be documented! But I guess I should work in both ways. This behaviour is introduced with r10062.

Change History (5)

comment:1 Changed 6 years ago by casseen

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Version changed from 1.0 to SVN

comment:2 Changed 6 years ago by casseen

  • Component changed from Uncategorized to Forms

comment:3 Changed 6 years ago by casseen

Last line of description should say:

[...] But I guess *it* should work in both ways. [...]

comment:4 Changed 6 years ago by kmtracey

  • Resolution set to invalid
  • Status changed from new to closed

It looks to me like your sequence version is broken by virtue of the fact that you have left off the trailing comma for your single-element tuple. If that is not the cause of the problem, you may reopen but please include some details of what 'broken form' means.

comment:5 Changed 6 years ago by casseen

Ok, a final comma clears this case! I am sorry. Still learning python as you see ; ) I was confused because it worked without a final comma before r10062.

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