DeferredAttribute object in form

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DeferredAttribute object in form

Kean Dumba
Hi,

New to Django, struggling at every point, but still learning.

I have created an edit form, however when I run the edit, the below response is returned to all object fields in the form, allbeit suffix varies.

<django.db.models.query_utils.DeferredAttribute object at 0x10d9d60d0>

Please see my views.py

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

Please advise if anyone has seen this issue, cause and resolution?

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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d9b83ad6-6665-486d-b739-f76c846a383c%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: DeferredAttribute object in form

salimon jamiu olashile
It seems the model & form class names are clashing. If you want use the same name, you can import each module as a whole.

Edited:

from . import models, forms

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFhdOCNUFeHnuF409CZQ%2BL9dB-p-D6CU3s_sso%2BGsZhsOqX3cg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: DeferredAttribute object in form

Kean Dumba
Hi Salimon, 

Thank you for the code and help.
When I update to your code I get the following error in the browser

Exception Type:AttributeError
Exception Value:
'ModelFormOptions' object has no attribute 'concrete_fields'
Im not sure why 

my models.py

class Businessownercreate(models.Model):
Creator = models.CharField(max_length=20)
Micro_Small_Medium = models.CharField(max_length=6)
Business_Name = models.CharField(max_length=20)
Owner_Firstname = models.CharField(max_length=20)
Owner_Surname = models.CharField(max_length=20)
Companies_House_Number = models.CharField(max_length=8)
Address_Line_1 = models.CharField(max_length=30)
Address_Line_2 = models.CharField(max_length=30)
Town = models.CharField(max_length=20)
City = models.CharField(max_length=20)
County = models.CharField(max_length=20)
Postcode = models.CharField(max_length=10)
Email = models.EmailField(max_length=50)
Phone = models.CharField(max_length=15)
Mobile = models.CharField(max_length=15)
Created_date = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self(Creator)

Pls advise if this is an error with my model?

Best,

K

On 18 Aug 2019, at 01:47, salimon jamiu olashile <[hidden email]> wrote:

It seems the model & form class names are clashing. If you want use the same name, you can import each module as a whole.

Edited:

from . import models, forms

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFhdOCNUFeHnuF409CZQ%2BL9dB-p-D6CU3s_sso%2BGsZhsOqX3cg%40mail.gmail.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/C362552D-AF16-419A-8A6A-AF378822DB75%40gmail.com.