Exemplo n.º 1
0
def add(request):
	if request.method == 'POST':
		form = ProductProfileForm(request.POST)
		if form.is_valid():
			c = form.save(commit=False)
			c.user = request.user
			c.save()
			return HttpResponseRedirect('/accounts/products')
	else:
		form = ProductProfileForm()
	return render(request, 'products/add.html', {'form': form})
Exemplo n.º 2
0
def edit(request, product_id):
	if request.method == 'POST':
		instance = ProductProfile.objects.get(pk=product_id)
		form = ProductProfileForm(request.POST, instance=instance)
		if form.is_valid():
			c = form.save(commit=False)
			c.save()
			return HttpResponseRedirect('/accounts/products/')
	else:
		try:
	 		product = ProductProfile.objects.get(pk=product_id) 
			form = ProductProfileForm(instance=product)
	 	except ProductProfile.DoesNotExist:
			return HttpResponse(u'产品信息不存在')

	return render(request, 'products/edit.html', {'form': form, 'product': product})