Skip to content

Commit

Permalink
1st Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rhshurov64 committed Jul 26, 2023
0 parents commit ec1d1fb
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions main/views.py
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})

0 comments on commit ec1d1fb

Please sign in to comment.