Best Python code snippet using autotest_python
views.py
Source:views.py
1from django.shortcuts import render2from visitor_app.models import VisitFor,Department,Visitor,Visit3from visitor_app.forms import VisitForm4from django.http import HttpResponseRedirect5def visit_index(request):6 visit = Visit.objects.all()7 context = {8 'visit': visit9 }10 return render(request, 'visit_index.html', context)11def create_visit(request):12 form = VisitForm()13 if request.method == "POST":14 form = VisitForm(request.POST)15 context = {16 'form':form17 }18 return render(request, "visit_create.html",context)19def save_visit(request):20 form = VisitForm()21 22 visitor = Visitor.objects.filter(pk=request.POST["name"])23 visitfor = VisitFor.objects.filter(pk=request.POST["visit_to"])24 department = Department.objects.filter(pk=request.POST["department"])25 # if not department:26 # department = Department(27 # department_name=request.POST["department"].department_name)28 # department.save()29 # if not visitfor:30 # visitfor = VisitForm(31 # name=request.POST["visit_to"].vis,32 # )33 # visitfor.save()34 35 visit = Visit(36 visitor_name= visitor[0],37 visitor_email = request.POST["email"],38 visitor_phone = request.POST["phone"],39 visit_to = visitfor[0],40 department = department[0],41 purpose = request.POST["purpose"]42 )43 visit.save()44 latest_visit = Visit.objects.all()45 context = {46 'visit':latest_visit47 }...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!