def addCrime(request): if request.method == 'GET': form = CrimeForm() else: form = CrimeForm(request.POST) if form.is_valid(): #form.save() crime = Crime(category_id=request.POST["category"],timedate=request.POST["timedate"],location_id=request.POST["location"],suspect_id=request.POST["suspect"]) crime.save() m = Crime_Agent(agent_id=request.POST["agent"],crime_id=crime.id) m.save() return HttpResponseRedirect('crimelist') return render(request,'crime/addcrime.html', {'form': form})
def updateCrime(request,id): crime = Crime.objects.get(id=id) #book_author = BookAuthor.objects.get(author=georfe, book=great_american_novel) #ag = Crime_Agent.objects.get(crime_id=id) if request.method == 'GET': form = CrimeForm(instance = crime) else: form = CrimeForm(request.POST,instance = crime) if form.is_valid(): #crime = form.save(commit=False) crime.category_id = request.POST["category"] crime.timedate = request.POST["timedate"] crime.location_id = request.POST["location"] crime.suspect_id = request.POST["suspect"] crime.status= request.POST["status"] crime.save() m = Crime_Agent(agent_id=request.POST["agent"],crime_id=crime.id) m.save() return HttpResponseRedirect('crimelist') return render(request,'crime/updatecrime.html',{'crime':crime,'form':form,'action':'update/'+id})