def add_headquarter(request): if request.method == 'POST': form = HeadquarterForm(request.POST, request.FILES) if form.is_valid(): form.save() return HttpResponseRedirect('/headquarters') else: form = HeadquarterForm() return render_to_response('headquarters.html', {'form':form}, context_instance = RequestContext(request))
def edit_headquarter(request, id_headquarter): headquarter = Headquarter.objects.get(pk = id_headquarter) if request.method == 'POST': mageField = headquarter.headquarter_image form = HeadquarterForm(request.POST, request.FILES, instance = headquarter) if form.is_valid(): form.save() if headquarter.headquarter_image != mageField: default_storage.delete(mageField) return HttpResponseRedirect('/headquarters') else: form = HeadquarterForm(instance = headquarter) return render_to_response('headquarters.html', {'form':form}, context_instance = RequestContext(request))