I'm with the same problem.. I've looked at the code of the form_for_intance function and saw something about the formfield_calback..
Looks like we must suply a function that sets the initial of each field.. But I'm not sure.. Any way... If you find something, please let me now.. []'s Luciano Adamiak On Mar 28, 7:07 pm, Gary Wilson <[EMAIL PROTECTED]> wrote: > Starting to play around with newforms and I am trying to create a form > with fewer fields than the model and post-fill those fields in the view. > With the following example models and form: > > class Book(models.Model): > author = models.CharField(maxlength=100, blank=True) > title = models.CharField(maxlength=100) > > class BookForm(forms.Form): > title = forms.CharField() > > From looking at the code, I was lead to believe I could do something > like this: > > book = Book.objects.get_or_create(author='me', title='go')[0] > form = forms.form_for_instance(book, form=BookForm)() > > The form rendered the single title field, but didn't set it's initial > value to "go". It appears thatform_for_instanceis creating all the > form fields for the model (with correct initial values), but the > creation of the new form type in the last line ofform_for_instance() > blows away the fields just created inform_for_instance() with the > base_fields created in DeclarativeFieldsMetaclass.__new__. > > Does the form parameter to theform_for_instance() only intended to > accept forms inheriting BaseForm and not Form? The docstring does > mention BaseForm. If this is the case, then what is best way to make a > form with fewer fields than the model? Removing them from form.fields > after instantiating my form instance and overriding the save() method of > my custom form to insert the desired values after my form has been > validated? > > Gary --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---