Re: AttributeError 'QuerySet' object has no attribute '_meta'

2019-08-18 Thread Kean Dumba
Ok thanks is there a way to call all objects, as this is more user friendly
and efficient when potentially editing many object fields?

On Sun, 18 Aug 2019 at 18:05, Daniel Roseman  wrote:

> You can't pass *all* the objects to the form. You have to get the specific
> one you want to edit and pass that as the instance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/e78cfd54-9800-4c17-b8a4-0ffaf5ddcfd4%40googlegroups.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKvrVZO_rKiPOm9ZLZ%2BmiUpTgUy-xim%2Br7s8kRWskThHtndjpw%40mail.gmail.com.


AttributeError 'QuerySet' object has no attribute '_meta'

2019-08-18 Thread Daniel Roseman
You can't pass *all* the objects to the form. You have to get the specific one 
you want to edit and pass that as the instance.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e78cfd54-9800-4c17-b8a4-0ffaf5ddcfd4%40googlegroups.com.


AttributeError 'QuerySet' object has no attribute '_meta'

2019-08-18 Thread Kean
Hi,

New to Django but trying to stick with it.

I have created a model form, which creates ok.

I am trying to edit records. I have the following, but keep getting the 
QuerySet object has no attribute '_meta' in the browser.

my views.py

def editbusiness(request):
data = models.Businessownercreate.objects.all() 
if request.method == "POST": 
form = forms.Businessownercreate(request.POST, instance=data)
if form.is_valid():
form.save()
return redirect("accounts:editremovebusiness")
else: 
form = forms.Businessownercreate(instance=data)
return render(request, 'editbusiness.html', context={ 'form':form })

my forms.py 

class Businessownercreate(forms.ModelForm):
class Meta:
model = Businessownercreate
fields = [ "Creator", "Micro_Small_Medium", "Business_Name", 
"Owner_Firstname", 
"Owner_Surname", "Companies_House_Number", "Address_Line_1", 
"Address_Line_2",
"Town", "City", "County", "Postcode", "Email", "Phone", "Mobile" ]

I'm have defined the meta, so i can't see why the query cant return the 
objects from the model to the form in this instance.

Please can anyone advise or help?

Best,

K



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e4d57f1-e41b-4692-8814-1c1888e563dc%40googlegroups.com.


Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Tomas Neme
The ArtworkForm AND the full view code would be helpful, yes

also, maybe you'll want to install django-extensions, werkzeug, and
run your devserver with runserver_plus, that'll give you full
debugging capabilities on your browser, and will be able to see what's
each object (that instace object, specifically)

-- 
"The whole of Japan is pure invention. There is no such country, there
are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Babatunde Akinyanmi
Like the code for ArtworkForm

On 7/26/12, Babatunde Akinyanmi <tundeba...@gmail.com> wrote:
> Looks good to me. Are you sure have shown us all the relevant parts of
> your code?
>
> On 7/25/12, Deathweasel <deathwea...@gmail.com> wrote:
>> Hello, guys.
>> This is Django 1.4.
>>
>> I have this code from my view:
>>
>> my_art = ArtworkModel.objects.get(id=pk)
>> comments = CommentModel.objects.filter(artwork=pk)
>> artForm = ArtworkForm(instance=my_art)
>> ...
>>
>> These models:
>>
>> class ArtworkModel(models.Model):
>> """
>> This class contains the information necessary to describe a piece
>> of
>> artwork uploaded to my website. Technically, the artist field is
>> unnecessary, but I'm throwing it in because I'd like to be able
>> to upload collaborations.
>> """
>> MEDIUMS = (('ink', 'ink'),
>>('graphite', 'graphite'),
>>('watercolor', 'watercolor'),
>>('oil', 'oil'),
>>('acrylic', 'acrylic'),
>>('digital', 'digital'),
>>('sculpture', 'sculpture'),
>>('other','other'))
>>
>> title = models.CharField(max_length=200)
>> medium = models.CharField(max_length=200, choices=MEDIUMS,
>> default='graphite')
>> upload_date = models.DateTimeField(auto_now_add=True)
>> artist = models.CharField(max_length=200)
>> image = models.ImageField(upload_to=getFilePath)
>> desc = models.TextField(verbose_name="Description", max_length=500)
>>
>> class Meta:
>> ordering = ['title']
>>
>> def __unicode__(self):
>> return '-'.join((self.title, self.artist, self.medium))
>>
>> class CommentModel(models.Model):
>> """
>> This class contains the information necessary to describe a
>> comment
>> that someone's left about a piece of artwork.
>> """
>> commenteer = models.CharField(max_length=200, blank=False)
>> comment_body = models.TextField(blank=False)
>> artwork = models.ForeignKey(ArtworkModel)
>> date = models.DateTimeField(auto_now_add=True)
>>
>> class Meta:
>> ordering = ['date']
>>
>>
>> And this traceback:
>> Traceback:
>> File
>> "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
>> in get_response
>>   111. response = callback(request,
>> *callback_args,
>>
>> **callback_kwargs)
>> File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py"
>> in
>>
>> _wrapped_view
>>   91. response = view_func(request, *args, **kwargs)
>> File "/home/deathweasel/shiny-website/deathweasel/artwork/views.py" in
>> modify_artwork
>>   94. artForm = ArtworkForm(instance=my_art)
>> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
>> __init__
>>   238. object_data = model_to_dict(instance, opts.fields,
>> opts.exclude)
>> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
>> model_to_dict
>>   111. opts = instance._meta
>>
>> Exception Type: AttributeError at /artwork/8/modify/
>> Exception Value: 'QuerySet' object has no attribute '_meta'
>>
>> The internet says I should be using a regular Model instance rather than
>> a
>> QuerySet to populate my form. The thing is that I think I AM using a
>> regular model. I'm not even using
>> those CommentModels yet. I don't understand why this is failing? Please
>> help?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msg/django-users/-/_eRwn1qmzr0J.
>> To post to this group, send email to django-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
> Sent from my mobile device
>

-- 
Sent from my mobile device

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-26 Thread Babatunde Akinyanmi
Looks good to me. Are you sure have shown us all the relevant parts of
your code?

On 7/25/12, Deathweasel <deathwea...@gmail.com> wrote:
> Hello, guys.
> This is Django 1.4.
>
> I have this code from my view:
>
> my_art = ArtworkModel.objects.get(id=pk)
> comments = CommentModel.objects.filter(artwork=pk)
> artForm = ArtworkForm(instance=my_art)
> ...
>
> These models:
>
> class ArtworkModel(models.Model):
> """
> This class contains the information necessary to describe a piece
> of
> artwork uploaded to my website. Technically, the artist field is
> unnecessary, but I'm throwing it in because I'd like to be able
> to upload collaborations.
> """
> MEDIUMS = (('ink', 'ink'),
>('graphite', 'graphite'),
>('watercolor', 'watercolor'),
>('oil', 'oil'),
>('acrylic', 'acrylic'),
>('digital', 'digital'),
>('sculpture', 'sculpture'),
>('other','other'))
>
> title = models.CharField(max_length=200)
> medium = models.CharField(max_length=200, choices=MEDIUMS,
> default='graphite')
> upload_date = models.DateTimeField(auto_now_add=True)
> artist = models.CharField(max_length=200)
> image = models.ImageField(upload_to=getFilePath)
> desc = models.TextField(verbose_name="Description", max_length=500)
>
> class Meta:
> ordering = ['title']
>
> def __unicode__(self):
> return '-'.join((self.title, self.artist, self.medium))
>
> class CommentModel(models.Model):
> """
> This class contains the information necessary to describe a comment
> that someone's left about a piece of artwork.
> """
> commenteer = models.CharField(max_length=200, blank=False)
> comment_body = models.TextField(blank=False)
> artwork = models.ForeignKey(ArtworkModel)
> date = models.DateTimeField(auto_now_add=True)
>
> class Meta:
> ordering = ['date']
>
>
> And this traceback:
> Traceback:
> File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py"
> in get_response
>   111. response = callback(request, *callback_args,
>
> **callback_kwargs)
> File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in
>
> _wrapped_view
>   91. response = view_func(request, *args, **kwargs)
> File "/home/deathweasel/shiny-website/deathweasel/artwork/views.py" in
> modify_artwork
>   94. artForm = ArtworkForm(instance=my_art)
> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
> __init__
>   238. object_data = model_to_dict(instance, opts.fields,
> opts.exclude)
> File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in
> model_to_dict
>   111. opts = instance._meta
>
> Exception Type: AttributeError at /artwork/8/modify/
> Exception Value: 'QuerySet' object has no attribute '_meta'
>
> The internet says I should be using a regular Model instance rather than a
> QuerySet to populate my form. The thing is that I think I AM using a
> regular model. I'm not even using
> those CommentModels yet. I don't understand why this is failing? Please
> help?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/_eRwn1qmzr0J.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
Sent from my mobile device

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



'QuerySet' object has no attribute '_meta' ... but I'm not using a QuerySet!

2012-07-25 Thread Deathweasel
Hello, guys.
This is Django 1.4.

I have this code from my view:

my_art = ArtworkModel.objects.get(id=pk)
comments = CommentModel.objects.filter(artwork=pk)
artForm = ArtworkForm(instance=my_art)
...

These models:

class ArtworkModel(models.Model):
"""
This class contains the information necessary to describe a piece of
artwork uploaded to my website. Technically, the artist field is
unnecessary, but I'm throwing it in because I'd like to be able
to upload collaborations.
"""
MEDIUMS = (('ink', 'ink'),
   ('graphite', 'graphite'),
   ('watercolor', 'watercolor'),
   ('oil', 'oil'),
   ('acrylic', 'acrylic'),
   ('digital', 'digital'),
   ('sculpture', 'sculpture'),
   ('other','other'))

title = models.CharField(max_length=200)
medium = models.CharField(max_length=200, choices=MEDIUMS, 
default='graphite')
upload_date = models.DateTimeField(auto_now_add=True)
artist = models.CharField(max_length=200)
image = models.ImageField(upload_to=getFilePath)
desc = models.TextField(verbose_name="Description", max_length=500)

class Meta:
ordering = ['title']

def __unicode__(self):
return '-'.join((self.title, self.artist, self.medium))

class CommentModel(models.Model):
"""
This class contains the information necessary to describe a comment
that someone's left about a piece of artwork. 
"""
commenteer = models.CharField(max_length=200, blank=False)
comment_body = models.TextField(blank=False)
artwork = models.ForeignKey(ArtworkModel)
date = models.DateTimeField(auto_now_add=True)

class Meta:
ordering = ['date']


And this traceback:
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" 
in get_response
  111. response = callback(request, *callback_args, 
**callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in 
_wrapped_view
  91. response = view_func(request, *args, **kwargs)
File "/home/deathweasel/shiny-website/deathweasel/artwork/views.py" in 
modify_artwork
  94. artForm = ArtworkForm(instance=my_art)
File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in 
__init__
  238. object_data = model_to_dict(instance, opts.fields, 
opts.exclude)
File "/usr/local/lib/python2.7/dist-packages/django/forms/models.py" in 
model_to_dict
  111.     opts = instance._meta

Exception Type: AttributeError at /artwork/8/modify/
Exception Value: 'QuerySet' object has no attribute '_meta'

The internet says I should be using a regular Model instance rather than a 
QuerySet to populate my form. The thing is that I think I AM using a 
regular model. I'm not even using
those CommentModels yet. I don't understand why this is failing? Please 
help?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/_eRwn1qmzr0J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread [EMAIL PROTECTED]

You can pass modelformset_factory a kwarg form which should just me
the form class you want to use(aka make a ModelForm with the changes
to the widgets).

Alex

On Nov 21, 7:25 pm, ayayalar <[EMAIL PROTECTED]> wrote:
> Karen,
>
> On this note, is it possible to customize the widget's for formsets as
> well?
>
> Thank you.
>
> On Nov 21, 3:23 pm, ayayalar <[EMAIL PROTECTED]> wrote:
>
> > 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
-~--~~~~--~~--~--~---



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

Karen,

On this note, is it possible to customize the widget's for formsets as
well?


Thank you.

On Nov 21, 3:23 pm, ayayalar <[EMAIL PROTECTED]> wrote:
> 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
-~--~~~~--~~--~--~---



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

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



Re: 'QuerySet' object has no attribute '_meta'

2008-11-21 Thread Karen Tracey
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
-~--~~~~--~~--~--~---



'QuerySet' object has no attribute '_meta'

2008-11-21 Thread ayayalar

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