예제 #1
0
파일: views.py 프로젝트: Cheekio/glean
def newCounty(request):
	if request.method == "POST":
		form = CountyForm(request.POST)
		if form.is_valid():
			new_save = County(**form.cleaned_data)
			new_save.save()
			return HttpResponseRedirect(reverse('counties:detailcounty', args=(new_save.id,) ))
		else:
			return render(request, 'counties/new_county.html', {'form':form, 'error':'Your County Form Was Not Valid'})
	else:
		form = CountyForm()
		return render(request, 'counties/new_county.html', {'form':form})
예제 #2
0
파일: views.py 프로젝트: Cheekio/glean
def editCounty(request, county_id):
	county = get_object_or_404(County, pk=county_id)
	if request.method == "POST":
		form = CountyForm(request.POST)
		if form.is_valid():
			new_save = County(**form.cleaned_data)
			new_save.id = county_id
			new_save.save()
			return HttpResponseRedirect(reverse('counties:index'))
		else:
			return render(request, 'counties/edit_county.html', {'form':form, 'county':county, 'error':'form needs some work', 'editmode':True})
	form = CountyForm(instance = county)

	return render(request, 'counties/edit_county.html', {'form':form, 'county':county, 'editmode':True})