On Sun, May 4, 2008 at 2:47 PM, Greg <[EMAIL PROTECTED]> wrote:

>
> Hello,
> I'm trying to use ModelForm to create a form based on one of my
> models.  However, I'm getting the following error:
>
> ///
> AttributeError at /plush/theone/
> 'ModelFormOptions' object has no attribute 'many_to_many'
> ///
>

For the future, it would be more helpful if you included the full traceback,
not just the last bit, when asking about errors like this.

Below is my code:
>
> ///
> Views.py File
>
> def theone(request):
>    a = TestForm()
>    if request.POST:
>        b = TestForm(data=request.POST, instance=a)


The instance parameter to a ModelForm is supposed to be an instance of the
model.  You are passing an instance of the ModelForm.


>        if b.is_valid():
>            b.save()
>        else:
>            assert False, "Errors"
>    else:
>        form = TestForm(instance=a)
>    return render_to_response('plush_mytest.htm', {'theform': form})
> ///
>
> ///
> Models.py File
>
> class MyTest(models.Model):
>    myfirst = models.CharField(max_length=100)
> ///
>
> ///
> myform.py file
>
> class TestForm(ModelForm):
>
>    class Meta:
>        model = MyTest
> ///
>
> ///
> plush_mytest.htm File
>
> <form method="POST" action="/plush/theone/" >
> {{ theform.myfield }}
> <input type="Submit" value="Submit" name="Submit" />
> </form>
> ///
>
>
> The error occurs when I get to the following line in my views.py file
> 'form = TestForm(instance=a)'.
>
> Anybody have any suggestions?


Your code needs to make a an instance of the model, if you want to edit an
existing model instance. If you don't need to edit an existing model
instance, than you don't need to use the instance model parameter at all.

Karen

--~--~---------~--~----~------------~-------~--~----~
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