tutorial 26 crud example

Solutions on MaxInterview for tutorial 26 crud example by the best coders in the world

showing results for - "tutorial 26 crud example"
Marwa
21 Aug 2019
1def create(request):
2    if request.method == 'POST':
3        form = ContactForm(request.POST)
4        if form.is_valid():
5            form.save()
6            return redirect('index')
7    form = ContactForm()
8
9    return render(request,'crudapp/create.html',{'form': form})
10
11def edit(request, pk, template_name='crudapp/edit.html'):
12    contact = get_object_or_404(Contact, pk=pk)
13    form = ContactForm(request.POST or None, instance=post)
14    if form.is_valid():
15        form.save()
16        return redirect('index')
17    return render(request, template_name, {'form':form})
18
19def delete(request, pk, template_name='crudapp/confirm_delete.html'):
20    contact = get_object_or_404(Contact, pk=pk)
21    if request.method=='POST':
22        contact.delete()
23        return redirect('index')
24    return render(request, template_name, {'object':contact})
25
similar questions
queries leading to this page
tutorial 26 crud example