示例#1
0
def createmarket(request, id):
	if request.method == 'POST':
		form = SupermarketForm(request.POST)
		rc = RequestContext(request)
		user = rc['user']
		if form.is_valid():
			name = form.cleaned_data['name']
			street = form.cleaned_data['street']
			zipcode = form.cleaned_data['zipcode']
			city = form.cleaned_data['city']
			description = form.cleaned_data['description']
			market = Supermarket(name=name, street=street, zipcode=zipcode, city=city, description=description, user=user)
			market.save()
			return HttpResponseRedirect('/market')
	else:
		form = SupermarketForm()
		return render_to_response('market/detail.')
示例#2
0
def market_edit(request, market_id):
	
	market = Supermarket.objects.get(id=market_id)
	
	if request.method == 'POST':
		form = SupermarketForm(request.POST, market)
		rc = RequestContext(request)
		if form.is_valid():
			market.name = form.cleaned_data['name']
			market.street = form.cleaned_data['street']
			market.zipcode = form.cleaned_data['zipcode']
			market.city = form.cleaned_data['city']
			market.description = form.cleaned_data['description']
			market.update()
			return HttpResponseRedirect('/market/detail.html?market_id=%s' % market.id)
	else:
		form = SupermarketForm(market)
		return render_to_response('market/edit.html', {
			'market': market,
		}, context_instance=RequestContext(request))