Opened 14 years ago
Closed 14 years ago
#14813 closed (invalid)
Order of fieldnames in exclude= (inside ModelForm) can mess things up
Reported by: | czartur | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | 1.2 |
Severity: | Keywords: | ||
Cc: | czepiel.artur@… | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've got a ModelForm that goes like this:
class TicketForm(forms.ModelForm): text = forms.CharField(widget = forms.Textarea(), label = _("Text")) class Meta: model = Ticket exclude=( 'last_responder_account', 'last_response_created_at' 'owner', 'owner_email', 'owner_language', 'owner_name', 'responses_count', 'status', )
Where last_responder_account
and owner
are both ForeignKeys and last_response_created_at
is DateTimeField.
Now... When i leave it as is, then in my template i see the form with fields (title, priority, department, owner, last_response_created_at and text.
Although when I change the order in exclude= to:
exclude=( 'last_responder_account', 'owner_email', 'owner_language', 'owner_name', 'responses_count', 'status', 'owner', 'last_response_created_at' )
I get only (title, priority, department and text) which is expected result.
However... When i change it again to:
exclude=( 'owner', 'last_response_created_at' 'last_responder_account', 'owner_email', 'owner_language', 'owner_name', 'responses_count', 'status', )
I get: (title, priority, department, last_responder_account, last_response_created_at, text)
(all things enclosed in parenthesis are in order)
Personally I think that ordering in exclude= shouldn't matter, but (as shown above) somehow it has some influence on form output.
You are missing a comma at the end of each 'last_response_created_at' line. This does not cause a problem when it is listed last, but it does when it is embedded in the list, since that line then gets combined with the next line, resulting in exclude listing a field that does not exist. Both affected lines are thus not excluded, which seems to be exactly what you have said is happening. Fix is to include the comma at the end of the line when the item is in the middle of the list.