Opened 18 years ago

Closed 18 years ago

#3247 closed defect (fixed)

Disable field creation in forms for hidden model fields

Reported by: mssnlayam@… Owned by: Adrian Holovaty
Component: Forms Version: dev
Severity: normal Keywords:
Cc: philipp.keller@…, bs1984@…, christian@…, yatiohi@… Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

django.newforms.models.form_for_model() should not create a form field for model fields declared with editable=False .

Attachments (3)

disable_formfield_for_hidden_fields.diff (1.7 KB ) - added by mssnlayam@… 18 years ago.
disable_formfield_for_hidden_fields_1.diff (1.8 KB ) - added by mssnlayam@… 18 years ago.
Patch from the root directory of django distribution, please ignore the previous patch.
disable_formfield_for_hidden_fields_trunk.diff (2.9 KB ) - added by Philipp Keller <philipp.keller@…> 18 years ago.
Patch matching 4451, included patch as well

Download all attachments as: .zip

Change History (18)

by mssnlayam@…, 18 years ago

by mssnlayam@…, 18 years ago

Patch from the root directory of django distribution, please ignore the previous patch.

comment:1 by Adrian Holovaty, 18 years ago

I'm not sure whether this should be the correct behavior. Is editable=False intended to be only for the admin site, or does it mean that field shouldn't be edited by *any* form?

comment:2 by Adrian Holovaty, 18 years ago

Summary: [patch] Disable field creation in forms for hidden model fields[patch] [design-q] Disable field creation in forms for hidden model fields

I'm putting [design-q] in the subject to designate "a design decision needs to be made here." It's just as a little experiment to see whether this extra tagging is useful.

comment:3 by Adrian Holovaty, 18 years ago

Summary: [patch] [design-q] Disable field creation in forms for hidden model fields[design-q] [patch] Disable field creation in forms for hidden model fields

Changed summary to put [design-q] first, to be consistent.

comment:4 by Philipp Keller <philipp.keller@…>, 18 years ago

I've read the following
http://www.b-list.org/weblog/2006/11/02/django-tips-auto-populated-fields:

The created and updated fields now have editable=False. This means that they will never show up in an automatic manipulator or in the admin. They’re still required, they just won’t be displayed anywhere. 

So I supposed this behaviour is meant for newforms too and just never got implemented.

But for the discussion: shouldn't be the other way round? I'd expect a editable=false field not to appear in a automatic generated form. I'd expect the form field list for admin in a configuration in the admin subclass.

comment:5 by Adrian Holovaty, 18 years ago

Summary: [design-q] [patch] Disable field creation in forms for hidden model fieldsDisable field creation in forms for hidden model fields
Triage Stage: UnreviewedDesign decision needed

comment:7 by Philipp Keller <philipp.keller@…>, 18 years ago

Triage Stage: Design decision neededAccepted

Since the discussion didn't bring up any objections against this solution, I switch triage to "accepted"

in reply to:  7 comment:8 by Michael Radziej <mir@…>, 18 years ago

Needs documentation: set
Needs tests: set
Patch needs improvement: set

Hi Philip, you're welcome to help out and triage tickets! But, please, go through everything as described in triage docs.

The patch in this ticket does not apply anymore (so I can't test it). Can you please update it? Tests and docs will be needed before it can be checked id, too.

by Philipp Keller <philipp.keller@…>, 18 years ago

Patch matching 4451, included patch as well

comment:9 by Philipp Keller <philipp.keller@…>, 18 years ago

Needs tests: unset
Owner: changed from Adrian Holovaty to anonymous
Patch needs improvement: unset
Status: newassigned
Version: SVN

Hi Michael, sorry, I forgot to add needs_docs and needs_tests to this ticket.
I did a new patch that matches the current trunk. I've also included a test in model_forms/models.py
It's quite hard to add documentation since the whole models.py isn't documented yet. Some time ago I wrote a tutorial on my blog (http://code.pui.ch/2007/01/07/using-djangos-newforms/) that could serve as a start point for adding documentation for the form_for_model and form_for_instance functions.
What do you think?

comment:10 by mir@…, 18 years ago

Owner: changed from anonymous to Adrian Holovaty
Status: assignednew

Thanks for the tests. The assigned field is to match tickets to core developers, please leave it as it is unless you know exactly what you're doing ;-)

comment:11 by Philipp Keller <philipp.keller@…>, 18 years ago

Cc: philipp.keller@… added

comment:12 by anonymous, 18 years ago

Cc: bs1984@… added

comment:13 by christian@…, 18 years ago

Cc: christian@… added

I have tested the patch (disable_formfield_for_hidden_fields_trunk.diff), and it seems to work fine.

comment:14 by anonymous, 18 years ago

Cc: yatiohi@… added

comment:15 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

(In [4548]) Fixed #3247 -- newforms form_for_model() and form_for_instance() no longer create form fields for database fields with editable=False. Thanks for the patch, mssnlayam@… and Philipp Keller

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