AttributeError 'QuerySet' object has no attribute '_meta'

1,712 views
Skip to first unread message

Kean

unread,
Aug 18, 2019, 12:31:45 PM8/18/19
to Django users
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



Daniel Roseman

unread,
Aug 18, 2019, 1:05:19 PM8/18/19
to Django users
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.

Kean Dumba

unread,
Aug 18, 2019, 1:09:10 PM8/18/19
to django...@googlegroups.com
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 <dan...@roseman.org.uk> 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...@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.
Reply all
Reply to author
Forward
0 new messages