Opened 13 years ago

Closed 12 years ago

Last modified 11 years ago

#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)

form_class_for_choices.patch (726 bytes ) - added by Rafał Jagoda 13 years ago.

Download all attachments as: .zip

Change History (8)

by Rafał Jagoda, 13 years ago

comment:1 by Rafał Jagoda, 13 years ago

Cc: Rafał Jagoda added

comment:2 by Andrew Godwin, 12 years ago

Component: Database layer (models, ORM)Forms
Patch needs improvement: set
Summary: formfield in Field class should allow change form_class if choices specifiedSpecifying choices to Field overrides any form_class argument
Triage Stage: UnreviewedAccepted
Type: New featureBug

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.)

comment:3 by Tomek Paczkowski, 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 Honza Král <Honza.Kral@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 10026c2ad0da99591567ba13afe4b489e050ca4a:

Merge pull request #804 from oinopion/ticket18162

Fixes #18162 -- Specifying choices to Field overrides any form_class argument

comment:5 by Carl Meyer, 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.

comment:6 by Carl Meyer <carl@…>, 11 years ago

In 7211741fc5d50425133ab942181cc095c56d7387:

Fixed #20999 - Allow overriding formfield class with choices, without subclass restrictions.

Refs #18162. Thanks claudep and mjtamlyn for review.

comment:7 by Carl Meyer <carl@…>, 11 years ago

In 21a3efcf48559b3336ca1743d94c741a82feffd6:

[1.6.x] Fixed #20999 - Allow overriding formfield class with choices, without subclass restrictions.

Refs #18162. Thanks claudep and mjtamlyn for review.

Backport of 7211741fc5d50425 from master.

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