problem with form

31 views
Skip to first unread message

Saeed Pooladzadeh

unread,
May 28, 2019, 7:22:30 PM5/28/19
to Django users
Hi

I'm trying to make a simple crud applicatio and learn from it. I wonder why my form can't save the data. Here cames my view:

from django.shortcuts import render
from saeed.forms import SmodelForm  
from saeed.models import Smodel
from django.shortcuts import render, redirect  



# Create your views here.
def emp(request):  
    if request.method == "POST":  
        form = SmodelForm(request.POST)  
        if form.is_valid():  
            try:  
                form.save()  
                return redirect('/show')  
            except  AssertionError as error:
                
                print(error)
                pass

     
                

                
    else:  
        form = SmodelForm()  
    return render(request,'saeed/index.html',{'form':form})  
#----------------------------------------
def show(request):  
    smodels = Smodel.objects.all()  
    return render(request,'saeed/show.html',{'smodels':smodels}) 
#----------------------------------------

def edit(request, id):  
    smodels = Smodel.objects.get(id=id)  
    return render(request,'saeed/edit.html', {'smodels':smodels})  
#-------------------------------------------

def update(request, id):  
    smodels = Smodel.objects.get(id=id)  
    form = SmodelForm(request.POST, instance = smodels)  
    if form.is_valid():  
        form.save()  
        return redirect("/show")  
    return render(request,'saeed/edit.html',{'smodels':smodels})  

#---------------------------------------------
def destroy(request, id):  
    smodels = Smodel.objects.get(id=id)  
    smodels.delete()  
    return redirect("/show")  


and here cames the complete app:



can you please inform me where is wrong?

thanks

thanks

Anirudh Jain

unread,
May 29, 2019, 12:19:02 AM5/29/19
to django...@googlegroups.com
Can you please send the screenshot or text of error. Also, try - form.save(commit=False)

--
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 post to this group, send email to django...@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/83aa34e2-2da1-432d-94ba-ec0beea90608%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Joe Reitman

unread,
May 29, 2019, 3:53:38 PM5/29/19
to Django users
Can you post the error?

Saeed Pooladzadeh

unread,
May 29, 2019, 4:29:36 PM5/29/19
to Django users
There is no error!! but the form doesn't save!! Let me know wich part you nead exactly.

در پنجشنبه 30 مهٔ 2019، ساعت 0:23:38 (UTC+4:30)، Joe Reitman نوشته:

Saeed Pooladzadeh

unread,
May 29, 2019, 5:13:04 PM5/29/19
to Django users
I sent detail on a new post "why form cant save""

در چهارشنبه 29 مهٔ 2019، ساعت 3:52:30 (UTC+4:30)، Saeed Pooladzadeh نوشته:
Reply all
Reply to author
Forward
0 new messages