#3727: save_instance raises KeyError when form_from_{model,instance} is 
supplied a
formfield_callback that does not return a formfield
---------------------------------------------------+------------------------
   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 have found a better way for writing this. More code, but more flexible:
 
 {{{
 #!python
 class MyForm(forms.Form):
     field1 = MyModel._meta.get_field('field1').formfield()
     field2 = MyModel._meta.get_field('field2').formfield()
 
     def save(self, **kwargs):
         instance = MyModel(**dict(self.clean_data, **kwargs))
         instance.save()
         return instance
 
 }}}
 
 Then views can do:
 {{{
 #!python
 form = MyForm(request.POST)
 if form.is_valid():
   instance = form.save(user=request.User)
   ...
 }}}

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