Wednesday, May 29, 2019

Re: problem with form

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 نوشته:
Can you post the error?

On Tuesday, May 28, 2019 at 6:22:30 PM UTC-5, Saeed Pooladzadeh wrote:
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

--
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/4b123677-3993-41d3-af97-1590da3fd09e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment