Friday, January 26, 2018

Re: unable to save object Django (2.0)

thank you the problem has being solve 

regards

On Friday, January 26, 2018 at 10:56:14 AM UTC+5:30, Omar Abou Mrad wrote:

On Tue, Jan 23, 2018 at 10:10 PM, harsh sharma <harshsha...@gmail.com> wrote:
i am trying to save the basic information about a person 
i have created a model form for it but i am unable to save the object (unable to update the database)

here is my views file
@login_required
def dashboard(request):
if request.method=="post":
form = linkform(request.POST)
if form.is_valid():
try:
notes = form.cleaned_data['note']
link = form.cleaned_data['link']
number = form.cleaned_data['number']
perso = person.object.create_person(notes,link,number)
perso.save()
return HttpResponse('succeess')
except:

Your "except" swallows the exceptions that are happening and you're unable
to figure out the reason it's failing.
 
class personmanager(models.Manager):
def create_person(self,note,link,number):
pers = self.create(note=note,link=link,number=number)
return pers


The problem is due to your use of "note" whereas the field name
is actually "notes" (plural)
 
Finally, the entire "create_person" serves no purpose as you're just
aliasing "create"

person.object.create_person(a=a, b=b, c=c)
Person.objects.create(a=a, b=b, c=c)

Regards,

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/efc92a9a-628e-4f4b-bd0b-248e01af8a52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment