Thanks Karen. That's exactly the case. Link you provided very helpful.

On Nov 21, 3:00 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Fri, Nov 21, 2008 at 4:22 PM, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > I am just simply trying to display all existing objects in a form
>
> > MODEL:
> > class Product(models.Model):
> >    name = models.CharField(max_length=30)
>
> >    def __unicode__(self):
> >        return self.name
>
> > VIEW
> > def product(request):
> >    product = Product.objects.all()
> >    form = ProductForm(instance=product)
> >    return render_to_response('index.html', {'form' : form})
>
> > Throws this error:
> > =============
>
> > Environment:
>
> > Request Method: GET
> > Request URL:http://localhost:8000/product/
> > Django Version: 1.0.1 final
> > Python Version: 2.5.2
> > Installed Applications:
> > ['django.contrib.auth',
> >  'django.contrib.contenttypes',
> >  'django.contrib.sessions',
> >  'django.contrib.sites',
> >  'demo.home']
> > Installed Middleware:
> > ('django.middleware.common.CommonMiddleware',
> >  'django.contrib.sessions.middleware.SessionMiddleware',
> >  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> > Traceback:
> > File "C:\Python25\lib\site-packages\django\core\handlers\base.py" in
> > get_response
> >  86.                 response = callback(request, *callback_args,
> > **callback_kwargs)
> > File "C:\Django\demo\..\demo\home\views.py" in product
> >  10.     form = ProductForm(instance=product)
> > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > __init__
> >  216.             object_data = model_to_dict(instance, opts.fields,
> > opts.exclude)
> > File "C:\Python25\Lib\site-packages\django\forms\models.py" in
> > model_to_dict
> >  119.     opts = instance._meta
>
> > Exception Type: AttributeError at /product/
> > Exception Value: 'QuerySet' object has no attribute '_meta'
>
> > Any suggestions?
>
> You don't show us ProductForm but I can guess it is a ModelForm for
> Product.  A ModelForm is designed to display and let you edit one individual
> object from the DB, not multiple.  Thus the 'instance' parameter to a model
> form is supposed to be one single instance of a model, not a QuerySet.  A
> model formset might be closer to what you are looking for:
>
> http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#id1
>
> 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