#4312: addition of defaults argument to newforms save()
-------------------------------+--------------------------------------------
Reporter:  [EMAIL PROTECTED]  |       Owner:  adrian         
  Status:  new                 |   Component:  django.newforms
 Version:  SVN                 |    Keywords:                 
   Stage:  Unreviewed          |   Has_patch:  1              
-------------------------------+--------------------------------------------
 I'd like the ability to call save() on a form and insert some values for
 fields (e.g., non-editable or to the instance before it is saved.  This
 way, calling save(False) to return an object which is subsequently
 manipulated then saved again can be avoided.  I'm not sure if 'defaults'
 is the best name for this argument, but that's what I've implemented for
 now.  For example:
 
 Given these models:
 {{{
 from django.db import models
 
 class Foo(models.Model):
     name = models.CharField(maxlength=16)
 
 class Bar(models.Model):
     name = models.CharField(maxlength=16)
     foo = models.ForeignKey(Foo, editable=False)
 
 }}}
 Here is the example:
 {{{
 >>> from django import newforms as forms
 >>> from mysite.myapp.models import *
 >>>
 >>> my_foo = Foo(name='My Foo')
 >>> my_foo.save()
 >>> Form1 = forms.form_for_model(Bar)
 >>> form = Form1({ 'name': 'My Bar'})
 >>> form.is_valid()
 True
 >>> form.save(defaults={ 'foo': my_foo })
 <Bar: Bar object>
 >>> Form2 = forms.form_for_model(Bar, fields=('baz'))
 >>> form = Form2({})
 >>> form.is_valid()
 True
 >>> form.save(defaults={ 'name': 'My Bar 2', 'foo': my_foo })
 <Bar: Bar object>
 >>>
 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/4312>
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