#3632 closed (wontfix)
initial values lost when calling newforms.form_for_instance() with a custom form arg
Reported by: | Owned by: | Thejaswi Puthraya | |
---|---|---|---|
Component: | Forms | Version: | dev |
Severity: | Keywords: | form_for_instance, decsprint01 | |
Cc: | gary.wilson@…, mtrier@…, larlet@… | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Initial values are lost when calling newforms.form_for_instance() with a custom form arg, eg
f = forms.form_for_instance(u)
is ok
f = forms.form_for_instance(u, form=MyCustomForm)
is not
The problem seems to be in DeclarativeFieldsMetaclass.new where the 'base_fields' attribute gets wiped out when using a custom form class. A tentative patch, probably broken as my understanding of metaclass programming is nil, attached to this ticket.
Attachments (6)
Change History (17)
by , 18 years ago
Attachment: | forms.diff added |
---|
comment:1 by , 18 years ago
None of the patches work, as the fields in both the custom form class and the one generated in form_for_instance() are the same.
comment:2 by , 18 years ago
Summary: | initial values lost when calling newforms.form_for_instance() with a custom form arg [patch] → [patch] initial values lost when calling newforms.form_for_instance() with a custom form arg |
---|
comment:3 by , 18 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:4 by , 18 years ago
Cc: | added |
---|
comment:5 by , 17 years ago
Cc: | added |
---|
comment:6 by , 17 years ago
Cc: | added |
---|
A recent discussion related to that on the devel list: http://groups.google.fr/group/django-developers/browse_thread/thread/92f84b1218b36ead/9980448c483a49c6
comment:7 by , 17 years ago
Owner: | changed from | to
---|
comment:8 by , 17 years ago
Keywords: | decsprint01 added |
---|---|
Triage Stage: | Accepted → Ready for checkin |
works with the patch of empty (Michael Trier).
comment:9 by , 17 years ago
Summary: | [patch] initial values lost when calling newforms.form_for_instance() with a custom form arg → initial values lost when calling newforms.form_for_instance() with a custom form arg |
---|
comment:10 by , 17 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
I don't think this is worth fixing. It adds some extra code for a case that is better handled in another way (we already take base_fields from parent classes, so this introduces a *third* way of altering base_fields; it's getting a bit out of hand).
#6337 fixes the edge pieces of this for ModelForms, so the fix for this problem is "use ModelForms", rather than us adding some extra code that would only be used by form_for_instance() and thus is deprecated the moment it lands in trunk.
Sorry if that seems a little harsh for those wanting this feature, but it's a matter of trying to only introduce code that will live a long and healthy life.
comment:11 by , 17 years ago
(In [7112]) Fixed #6337. Refs #3632 -- Fixed ModelForms subclassing, to the extent that it can be made to work.
This ended up being an almost complete rewrite of ModelForms.new, but
should be backwards compatible (although the text of one error message has
changed, which is only user visible and only if you pass in invalid code).
Documentation updated, also.
This started out as a patch from semenov (many thanks!), but by the time all
the problems were hammered out, little of the original was left. Still, it was
a good starting point.
tentative patch to newforms/forms.py