コード例 #1
0
ファイル: views.py プロジェクト: stianrincon/school
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))
コード例 #2
0
ファイル: views.py プロジェクト: stianrincon/school
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))