def update(request,id): employee = Employee.objects.get(id=id) form = EmployeeForm(request.POST, instance=employee) if form.is_valid(): form.save() return redirect('/show') return render(request,"edit.html",{'employee':employee})
def post(self, request): form = EmployeeForm(request.POST) if form.is_valid(): form.save() return redirect(index) return render(request, 'crud/create.html', {'form': form})
def update(request,id): employee=Employee.objects.get(id=id) form=EmployeeForm(request.POST) if form.is_valid(): form.save() return redirect("/show") return render(request,'edit.html', {'employee':employee})
def emp(request): if request.method == 'POST': form = EmployeeForm(request.POST) if form.is_valid(): form.save() else: form = EmployeeForm() return render(request, 'home.html', {'form': form})
def emp(request): if request.method == "POST": form = EmployeeForm(request.POST) if form.is_valid(): try: form.save() return redirect('/show') except: pass else: form = EmployeeForm() return render(request, 'index.html', {'form': form})
def emp(request): if request.method == "POST": form = EmployeeForm(request.POST) # here "form" is one varible if form.is_valid(): try: form.save() return redirect("/show") except: pass else: form = EmployeeForm() return render(request, "index.html", {'form': form})
def emp(request): if request.method=="POST": form=EmployeeForm(request.POST) regex = '^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$' employees = Employee.objects.all() dict=[] for employee in employees: dict.append(employee.eid) if form.is_valid() and form.data['eid'] in dict: return render(request,"eid.html",{'form':form}) if form.is_valid() and len(form.data['econtact'])==10 and re.search(regex,form.data['eemail'])!=None: try: form.save() return redirect("/show") except: pass else: return render(request,"error.html",{'form':form}) else: form=EmployeeForm() return render(request,"index.html",{'form':form})