コード例 #1
0
ファイル: views.py プロジェクト: JayDesai007/Django_CRUD
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})
コード例 #2
0
    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})
コード例 #3
0
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})
コード例 #4
0
ファイル: views.py プロジェクト: nabinstha1234/djdemo
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})
コード例 #5
0
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})
コード例 #6
0
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})
コード例 #7
0
ファイル: views.py プロジェクト: JayDesai007/Django_CRUD
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})