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 that form_for_instance is creating all the 
form fields for the model (with correct initial values), but the 
creation of the new form type in the last line of form_for_instance() 
blows away the fields just created in form_for_instance() with the 
base_fields created in DeclarativeFieldsMetaclass.__new__.

Does the form parameter to the form_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
-~----------~----~----~----~------~----~------~--~---

Reply via email to