﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
4312	addition of defaults argument to newforms save()	ctdecci@…	Adrian Holovaty	"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>
>>>                                                                    
}}}"		closed	Forms	dev		wontfix			Design decision needed	1	0	0	0	0	0
