コード例 #1
0
ファイル: views.py プロジェクト: kstumpf/location_demo
def prov_edit(request, pk):
    '''A model form for editing the proverb.'''
    proverb = Proverb.objects.get(pk=pk)
    if request.POST:
        form = ProverbForm(request.POST, instance = proverb)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return render(request, 'prov_list.html')
            else:
                return redirect('/prov_list/')
    else:
        form = ProverbForm(instance = proverb)

    context = {}
    context.update(csrf(request))
    context['form'] = form
    context['pk'] = pk

    return render_to_response('prov_edit.html', context)
コード例 #2
0
ファイル: views.py プロジェクト: kstumpf/location_demo
def prov_create(request):
    '''A model form for creating a new proverb.'''
    if request.method == 'POST':
        form = ProverbForm(request.POST)
        if form.is_valid():
            form.save()
            if request.is_ajax():
                return render(request, 'prov_list.html')
            else:
                return redirect('/prov_list/')
    else:
        form = ProverbForm() 

    continent_list = Location.objects.filter(type="continent")

    context = {}
    context.update(csrf(request)) 
    context['form'] = form
    context['continent_list'] = continent_list

    return render_to_response('prov_create.html', context)