-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ec1d1fb
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from django.shortcuts import render,HttpResponseRedirect, redirect | ||
from .forms import AddForm | ||
from .models import AddUser | ||
|
||
# Create your views here. | ||
|
||
|
||
# Add and Show | ||
def home(request): | ||
if request.method == 'POST': | ||
fm = AddForm(request.POST) | ||
if fm.is_valid(): | ||
nm = fm.cleaned_data['name'] | ||
em = fm.cleaned_data['email'] | ||
ag = fm.cleaned_data['age'] | ||
rg = AddUser(name=nm,email=em,age=ag) | ||
rg.save() | ||
fm = AddForm() | ||
else: | ||
fm = AddForm() | ||
list = AddUser.objects.all() | ||
return render(request, 'main/show.html', {'form':fm, "li":list}) | ||
|
||
# Delete | ||
def delete_data(request,id): | ||
if request.method =='POST': | ||
pi = AddUser.objects.get(pk=id) | ||
pi.delete() | ||
return HttpResponseRedirect('/') | ||
|
||
|
||
# Views for Update | ||
def update_data(request,id): | ||
if request.method =='POST': | ||
pi = AddUser.objects.get(pk=id) | ||
fm = AddForm(request.POST,instance=pi) | ||
if fm.is_valid(): | ||
fm.save() | ||
else: | ||
pi = AddUser.objects.get(pk=id) | ||
fm = AddForm(instance=pi) | ||
|
||
return render(request,'main/update.html',{'form':fm}) |