#18162 closed Bug (fixed)
Specifying choices to Field overrides any form_class argument
Reported by: | Rafał Jagoda | Owned by: | nobody |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Rafał Jagoda | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
In django.db.models.fields.Field (and derivatives) function formfield allow changing form_class when method is invoked manually. But changing form_class when 'choices' specified is impossible.
I attach patch which add 'form_class_for_choices' in function kwargs.
Attachments (1)
Change History (8)
by , 13 years ago
Attachment: | form_class_for_choices.patch added |
---|
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Component: | Database layer (models, ORM) → Forms |
---|---|
Patch needs improvement: | set |
Summary: | formfield in Field class should allow change form_class if choices specified → Specifying choices to Field overrides any form_class argument |
Triage Stage: | Unreviewed → Accepted |
Type: | New feature → Bug |
comment:3 by , 12 years ago
I've made an effort to fix this in proposed way. The problem is, Django depends on ignoring given form_class
, for example IntegerField.formfield
passes form_class
regardless of choices. Here is my branch, where I added override, where subclasses of TypedChoiceField
are not ignored. This preserves current behaviour while adding some flexibility: https://github.com/oinopion/django/compare/ticket18162
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:5 by , 11 years ago
Just FYI for anyone involved with this ticket, I've opened #20999 to make the case that the wrong fix was applied here, and rather than unnecessarily-restrictive type checking we should instead use rafallo's original patch respecting a new keyword argument.
Valid bug, but attached patch is not what I would do - instead, just make it respect form_class if provided (by changing the default value so assignment of it is detectable.)