#3727: form_for_model and form_for_instance should be able to exclude certain
fields
---------------------------------------------------+------------------------
   Reporter:  Matias Hermanrud Fjeld <[EMAIL PROTECTED]>  |                
Owner:  adrian                
     Status:  new                                  |            Component:  
django.newforms       
    Version:  SVN                                  |           Resolution:      
                  
   Keywords:                                       |                Stage:  
Design decision needed
  Has_patch:  1                                    |           Needs_docs:  1   
                  
Needs_tests:  1                                    |   Needs_better_patch:  0   
                  
---------------------------------------------------+------------------------
Comment (by Matias Hermanrud Fjeld <[EMAIL PROTECTED]>):

 I've attached a new patch, newforms_save_instance.diff. This changes
 django.newforms.models.save_instance to only update fields that have
 corresponding data in clean_data. With this applied, I can write:
 
 {{{
 #!python
 form_for_model(User, formfield_callback=lambda f, **kwargs: f.name in
 ('company', 'someotherfield') and f.formfield(kwargs**))
 }}}
 
 It seems to me that adrian intended the the formfield callback to be able
 to keep fields out of the form by returning a value evaluating to false.
 From django/newforms/models.py, lines 97-99:
 
 {{{
 #!python
         formfield = formfield_callback(f, initial=current_value)
         if formfield:
             field_list.append((f.name, formfield))
 }}}
 
 The problem is that if there is no field in the form corresponding to a
 field in the model, save_instance raises a KeyError. This patch fixes
 this, but would break code that depends on this behavior.
 
 Maybe adrian could comment on how he intended this to work?

-- 
Ticket URL: <http://code.djangoproject.com/ticket/3727#comment:3>
Django Code <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