def create(request): if request.method == 'GET': if Demand.objects.all().count() == 0: Demand.objects.create(type='雲端') Demand.objects.create(type='大數據') Demand.objects.create(type='智慧製造') Demand.objects.create(type='物聯網') Demand.objects.create(type='系統開發') Department.objects.create(name='資管') Department.objects.create(name='資工') Department.objects.create(name='資通') Teacher.objects.create(name='唐元亮') return render(request, 'visits/createVisits.html', {'visitForm': VisitForm()}) #POST visitsForm = VisitForm(data=request.POST) if not visitsForm.is_valid(): return render(request, 'visits/createVisits.html', {'visitForm': visitsForm}) visitsForm.save() return redirect(reverse('visits:visits'))
def getVisit(request, visitID): visit = VisitModel.objects.get(id=visitID) visit = VisitForm(instance=visit) return render(request, 'visits/visit.html', {'visitForm': visit})