#14119: fields_for_model returns all fields when fields parameter is the empty
tuple
-------------------------+--------------------------------------------------
 Reporter:  alexdutton   |       Owner:  nobody    
   Status:  new          |   Milestone:            
Component:  Forms        |     Version:  1.2       
 Keywords:  model forms  |       Stage:  Unreviewed
Has_patch:  1            |  
-------------------------+--------------------------------------------------
 When attempting to use `modelformset_factory` to generate forms where the
 user can only delete objects (i.e. not edit them), one would expect a
 `fields=()` to create forms with only delete checkboxes. However,
 `fields_for_model` uses the following check to determine whether to
 restrict fields:

 {{{
 #!python
  if fields and not f.name in fields:
      continue
 }}}

 When passed the empty tuple, fields are never skipped as bool( () ) ==
 False, resulting in all fields being displayed.

 This should be:

 {{{
 #!python
  if fields is not None and not f.name in fields:
      continue
 }}}

 I've attached a patch for both `construct_instance` (which also has the
 wrong behaviour) and `fields_for_model`.

 The additional regression tests cover `construct_instance`,
 `fields_for_model`, `modelformset_factory` and `ModelForm`. The latter is
 included even though the usage of `fields=()` in the this case is arguably
 nonsensical.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14119>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to