Gary,
after some testing I came to this solution:
I created my own form_for_instance function like this:
def form_for_instance(instance):
f = forms.models.form_for_instance(instance=instance, form=MyCustomForm)
f.base_fields['email'].initial=instance.email
...
>From what I remember you do:
def myformcallback(f, **args):
exclude = ['author']
if f.name in exclude:
return None
return f.formfield(**args)
MyForm = form_for_instance(book, formfield_callback=myformcallback)
if request.POST:
form = MyForm(request.POST)
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
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 =
4 matches
Mail list logo